思路:先异或再统计结果中1的个数。
代码:
class Solution {
public int hammingDistance(int x, int y) {
int count = 0;
int z = x^y;
for (int i = 0; i < 32; i++) {
if (((z>>>i)&1) == 1) {
count++;
}
}
return count;
}
}