LeetCode HOT100 - 汉明距离

异或得到二进制上不同的数

接着用 popcount 数这个数二进制中的 1 的个数

class Solution {
public:
    int hammingDistance(int x, int y) {
        x ^= y;
        return __builtin_popcount(x);
    }
};
posted @ 2026-03-26 14:26  rdcamelot  阅读(13)  评论(0)    收藏  举报