java solution


  • 0
    M
    public int hammingDistance(int x, int y) {
            int himmingDistance = 0;
            while(x != 0 || y != 0) {
                if((x & 1) != (y & 1)) {
                    ++himmingDistance;
                }
                x >>= 1;
                y >>= 1;
            }
            return himmingDistance;
        }

Log in to reply
 

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