12345678910111213141516171819202122232425 |
- /**
- * @param {number} x
- * @param {number} y
- * @return {number}
- */
- function countOnesBits(x) {
- var result = 0;
- while (x > 0) {
- if (x % 2 === 1) {
- result++;
- }
- x = x >> 1;
- }
- return result;
- }
- function hammingDistance(x, y) {
- return countOnesBits(x ^ y);
- }
|