My C++ easy understand solution


  • 2
     int hammingDistance(int x, int y) {
            int xorr = x ^ y;
            int dig = 0;
            while(xorr > 0){
                dig += xorr & 1;
                xorr >>= 1;
            }
            return dig;
    }
    

Log in to reply
 

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