Description
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Note:
0 ≤ x, y < 2^31.
The original problem is here.
My Solution
I solve this problem in C++, as below:
1 | class Solution { |
Note
To solve the problem, convert the integer to binary and compare the every bit.