实际就是按位异或运算后,统计 1 的个数。
1
function hammingDistance(x: number, y: number): number { let count = 0 let xor = x ^ y while (xor) { xor &= xor - 1 count++ } return count }