1. 程式人生 > >leetcode 461. Hamming Distance

leetcode 461. Hamming Distance

distance leet min code return while etc ret clas

class Solution {
public:
    int hammingDistance(int x, int y) {
        int res = x ^ y;
        int count = 0;
        int m;
        while(res){
            m = res & (res - 1);
            count++;
            res = m;
        }
        return count;
    }
};

leetcode 461. Hamming Distance