2025-07-29 15:55:38 +0000 UTC

Hamming Distance

Code

class Solution:
    def hammingDistance(self, x: int, y: int) -> int:
        count = 0
        while x or y:
            if x % 2 != y % 2:
                count += 1
            x //= 2
            y //= 2
        return count