Hamming Distance Solution(c++)


  • 0
    H

    int hammingDistance(int x, int y) {
    int a = x^y;
    int distance = 0;
    while (a != 0) {
    if (a % 2 != 0) {
    distance++;
    }
    a >>= 1;
    }
    return distance;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.