Python 100%, inspired by Fenwick tree


  • 0
    R
    class Solution(object):
        def hammingDistance(self, x, y):
            xor = x ^ y
            res = 0
            while xor > 0:
                xor -= xor & -xor
                res += 1
            
            return res
    

Log in to reply
 

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