Hamming Distance C++


  • 0
    K

    class Solution {
    public:
    int hammingDistance(int x, int y) {
    int a= x^y;
    int count = 0;
    while(a>0){
    if(a%2==1){
    count++;
    }
    a = a/2;
    }
    return count;
    }
    };


Log in to reply
 

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