LeetCode Hamming Distance
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 |
|
Note
To solve the problem, convert the integer to binary and compare the every bit.
LeetCode Hamming Distance
http://zhaoshuaijiang.com/2017/01/10/leetcode-hamming-distance/