461. Hamming Distance
2018-06-24 本文已影响3人
fred_33c7
题目地址:https://leetcode.com/problems/hamming-distance/description/
大意:求两个int型整数的汉明距离(Hamming Distance)
比较简单,两个二进制数的疑惑然后求1的个数。
# 461. Hamming Distance
class Solution:
def hammingDistance(self, x, y):
"""
:type x: int
:type y: int
:rtype: int
"""
return bin(x^y).count('1')
a = Solution()
print (a.hammingDistance(1,4))