Hamming Distance
Easy
Math
Bit Manipulation
Given two integers x and y, return the Hamming distance (number of differing bits).
Constraints
0 ≤ x, y ≤ 2^31 - 1
Examples
Example 1:
Input: 1
4
Output: 2
Explanation: 1=001, 4=100, differ in 2 positions
Example 2:
Input: 3
1
Output: 1
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console