leetcode-easy-others-461. Hamming Distance

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")
原文地址:https://www.cnblogs.com/rosyYY/p/11004745.html