题目:
The Hamming Distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
代码:
/**
* @param {number} x
* @param {number} y
* @return {number}
*/
var hammingDistance = function(x, y) {
var n = 0, s = x ^ y;
for(n = 0; n < s; n++){
s &= (s - 1)
}
return n;
};