My Python solution


  • 0
    Y
        def hammingDistance(self, x, y):
            distance = 0
            xor_result = x ^ y
            while xor_result != 0:
                distance += xor_result & 1
                xor_result = xor_result >> 1
            return distance
    

Log in to reply
 

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