My python solution, beats 100%, i didn't use xor


  • 0
    I
        def hammingDistance(self, x, y):
            """
            :type x: int
            :type y: int
            :rtype: int
            """
            hamming_dist = 0
            while x or y:
                if x % 2 != y % 2:
                    hamming_dist += 1
                x >>= 1
                y >>= 1
            return hamming_dist

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.