Closed congr closed 5 years ago
class Solution {
public int hammingDistance(int x, int y) {
int n = x ^ y;
int cnt = 0;
for (int i = 0; i < 32; i++) cnt += (n >> i) & 1;
return cnt;
}
}
class Solution {
public int hammingDistance(int x, int y) {
return Integer.bitCount(x ^ y);
}
}