def findComplement(self, num: int) -> int: rst = shift = 0 while num: rst = ((num&1)^1) << shift | rst num >>= 1 shift += 1 return rst