LeetCode HOT100 - 汉明距离
异或得到二进制上不同的数
接着用 popcount 数这个数二进制中的 1 的个数
class Solution {
public:
int hammingDistance(int x, int y) {
x ^= y;
return __builtin_popcount(x);
}
};
异或得到二进制上不同的数
接着用 popcount 数这个数二进制中的 1 的个数
class Solution {
public:
int hammingDistance(int x, int y) {
x ^= y;
return __builtin_popcount(x);
}
};