LeetCode 461. 汉明距离

穿过雾的阴霾 / 2023-07-31 / 原文

class Solution {
public:
    int hammingDistance(int x, int y) {
        int cnt=0;
        int t=x^y;
        while(t)
        {
            cnt+=(t&1);
            t>>=1;
        }
        return cnt;
    }
};