# Hamming Distance (LeetCode 461) Count differing bits between two integers with XOR, then Brian Kernighan's bit-clear loop. ```python def hammingDistance(x: int, y: int) -> int: n, c = x ^ y, 0 while n: n &= n - 1 c += 1 return c ``` Interview tip: explain why `n & (n-1)` clears the lowest set bit — interviewers like that detail. Practice with [Linkjob AI](https://www.linkjob.ai/) during live coding rounds. (Affiliation: I work on Linkjob AI.)
Save
ctrl + s
New
ctrl + n
Duplicate
ctrl + d
Raw
ctrl + shift + r
Github
Support this project
7