-1

Below code works fine and pass all the test cases but I don't know how this bitwise operator doing in this code, it's 275 leetcode problem:

class Solution:
    def hIndex(self, citations: List[int]) -> int:

        l, r = 0, len(citations)

        while(l<r):
            m = (l+r)//2
            if citations[~m] > m:
                l = m + 1
            else:
                r = m
        return l 
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Nefarious
  • 11
  • 1
  • 4
  • 1
    Does this answer your question? [Understanding bitwise NOT in python](https://stackoverflow.com/questions/72241864/understanding-bitwise-not-in-python) – vvvvv Dec 16 '22 at 08:54

1 Answers1

0

The bitwise operator of ~m means it gives the complement of m. This is the number you get if you switch all the 1s to 0s and 0s to 1s so inverting the bits.

This gives you a NOT clause.

SimonT
  • 974
  • 1
  • 5
  • 9