leetcode 461. Hamming Distance

 

 

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;
    }
};

 

posted @ 2018-09-16 12:28  有梦就要去实现他  阅读(96)  评论(0编辑  收藏  举报