C++ Solution


  • 0
    B

    int hammingDistance(int x, int y) {

        int ans = 0;
        
        while(x > 0 || y > 0){
            
            if( (x & 1) ^ (y & 1)){
                ans++;
            }
            x >>= 1;
            y >>= 1;
        }
        return ans;
    }

Log in to reply
 

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