JuniorBit Manipulation
Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, return the Hamming distance between them.
Note: This question is the same as 2220: Minimum Bit Flips to Convert Number.
Example 1
Input
x = 1, y = 4Output
2The binary representations of 1 and 4 differ at two bit positions.
Example 2
Input
x = 3, y = 1Output
1The binary representations of 3 and 1 differ at one bit position.
Constraints
- 0 <= x, y <= 2^31 - 1