Skip to content

Latest commit

 

History

History
22 lines (19 loc) · 375 Bytes

File metadata and controls

22 lines (19 loc) · 375 Bytes
class Solution(object):
    def hammingDistance(self, x, y):
        """
        :type x: int
        :type y: int
        :rtype: int
        """
        ans = 0
        z = x ^ y
        while z > 0:
            if z % 2 == 1:
                ans += 1
                z = (z-1)/2
            else:
                z /= 2
        return ans

hamming distance