LeetCode 461. 汉明距离 原题思路代码运行截图收获 原题 LeetCode 461. 汉明距离 思路 汉明距离就是两个数异或后的二进制中1的数目 代码 class Solution { public: int hammingDistance(int x, int y) { int z = x ^ y; int ans = 0; while (z) { ans += (z & 1); z >>= 1; } return ans; } }; 运行截图 收获 统计二进制数中的1的数目可以用内置函数__builtin_popcount()来执行位运算很奇妙哈不得不说! & >>