Hamming Distance by Java


  • 0
    S
        public int hammingDistance(int x, int y) {
            int z = x ^ y;
            int count = 0;
            while (z > 0){
                if(z % 2 == 1) count ++;
                z = z >>> 1;
            }
            return count;
        }
    

Log in to reply
 

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