class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
return(bin(x^y).count('1'))
-
Python位运算符:^
当两对应的二进位相异时,结果为1
-
十进制转二进制:bin()
class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
return(bin(x^y).count('1'))
Python位运算符:^
当两对应的二进位相异时,结果为1
十进制转二进制:bin()