Solutions to high-frequency interview questions of LeetCode in C++17, taking into account both efficiency and comprehensibility.
class Solution {
public:
int hammingDistance(int x, int y) {
int t = x ^ y;
int res = 0;
while (t) {
++res;
t &= t - 1; // 将最低位的 1 改为 0
}
return res;
}
};