461 Hamming Distance

int hammingDistance(int x, int y) {
    int z = x^y;
    int count = 0;
    while(z){
        z = z&(z-1);
        count++;
    }
    
    return count;
}

你可能感兴趣的:(461 Hamming Distance)