原数和二进制全为1的数异或.
class Solution: def findComplement(self, num: int) -> int: size = len(bin(num)[2:]) - 1 t = 1 for _ in range(size): t = (t << 1) + 1 return num ^ t