Python Implementation


  • 0
    E

    Python implementation

    def hammingDistance(self, x, y):
            """
            :type x: int
            :type y: int
            :rtype: int
            """
            res = x^y
            count = 0
            while(res):
                count+= res & 1
                res >>= 1
            return count
    

Log in to reply
 

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