Java
public class Solution {
public int hammingDistance(int x, int y) {
int c=x^y;
int i;
for(i=0;c>0;i++)
{
c&=(c-1);
}
return i;
}
}
Java,很简练,用到了库函数
public class Solution {
public int hammingDistance(int x, int y) {
return Integer.bitCount(x ^ y);
}
}