1. 程式人生 > >LeetCode-461-漢明距離

LeetCode-461-漢明距離

韓明距離就是兩個二進位制數相應位置不同的個數

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