Simple C solution


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

Log in to reply
 

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