Python solution without using bitwise operations


  • 0
    R
    def hammingDistance(self, x, y):
            d = 0
            while x or y:
                d += (x + y) % 2
                x, y = x//2, y//2
            return d
    

Log in to reply
 

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