思路:
依次记录两个数字每位是否相同,如果不同,计数器加一。
class Solution {
public:
int hammingDistance(int x, int y) {
int count=0;
while(x||y)
{
if(x%2!=y%2) ++count;
x/=2;
y/=2;
}
return count;
}
};