https://leetcode-cn.com/problems/hamming-distance/

image.png
class Solution:
def hammingDistance(self, x: int, y: int) -> int:
return bin(x ^ y).count('1')
'''
bin() 返回一个整数 int 或者长整数 long int 的二进制表示(返回值是个字符串)
>>>bin(10)
'0b1010'
>>> bin(20)
'0b10100'
count() 方法用于统计字符串里某个字符出现的次数,使用方法:
str.count(sub, start= 0,end=len(string))
其中:
sub -- 搜索的子字符串
start -- 字符串开始搜索的位置。默认为第一个字符,第一个字符索引值为0。
end -- 字符串中结束搜索的位置。字符中第一个字符的索引为 0。默认为字符串的最后一个位置。
返回值:
子字符串在字符串中出现的次数
'''