异或 ^ 任何数于0异或为任何数 0 ^ n => n 相同的数异或为0: n ^ n => 0
与 & z&1 判断最后一位是否为1:为1是奇数,为0是偶数
‘>>’ 右移 等价于除以2
def singleNumber(self, nums):
a = 0
for num in nums:
a = a ^ num
return a
def hammingDistance(self, x: int, y: int) -> int:
res = 0
z = x^y
while z:
res+=z&1
z=z>>1
return res