mycode 92.05%
class Solution(object): def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int """ n = x ^ y cnt = 0 while n: n = n&(n-1) cnt += 1 return cnt
参考
class Solution(object): def hammingDistance(self, x, y): """ :type x: int :type y: int :rtype: int """ res = x ^ y res = bin(res) return res.count("1")