class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
a=bin(x^y) #异或
c=0
for i in range(len(a)):
if a[i] == "1":
c+=1
return c
leetcode - 461 - 汉明距离
最新推荐文章于 2022-10-20 14:30:13 发布
class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
a=bin(x^y) #异或
c=0
for i in range(len(a)):
if a[i] == "1":
c+=1
return c