LeetCode 461. 汉明距离

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;
    }
};
posted @ 2023-07-30 22:29  穿过雾的阴霾  阅读(10)  评论(0)    收藏  举报