C++ solution use bit manipulation


  • 0
    Y
    int hammingDistance(int x, int y) {
        int result = x ^ y;
        int count = 0;
            while(result > 0){
                if(result % 2 == 1)
                    count ++;
                result /= 2;
            }
        return count;
        }
    

Log in to reply
 

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