题目
题解
通过观察可以发现,汉明距离实际上就是按位异或的值相加的结果
class Solution {
public:
int hammingDistance(int x, int y) {
int temp = x ^ y;
int ans=0;
while(temp != 0){
ans += temp % 2;
temp /= 2;
}
return ans;
}
};