Easy to understand Python solution, 35ms runtime, accepted.


  • 0
    S
    class Solution(object):
        def hammingDistance(self, x, y):
            """
            :type x: int
            :type y: int
            :rtype: int
            """
            result = 0
            while (x > 0 or y > 0):
                x_last, y_last = x % 2, y % 2
                if (x_last != y_last):
                    result += 1
                x //= 2
                y //= 2
            return result
    

Log in to reply
 

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