clueless coding // TODO: be smarter

LeetCode Hamming Distance: CPP Solution



TL;DR Code Solution


int hammingDistance(int x, int y) {

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

}