Hamming Distance Java Solution


  • 0
    2
    class Solution {
        public int hammingDistance(int x, int y) {
            
            int xorOfNums = x ^ y ;
            int setBits = 0;
            
            while(xorOfNums>0) {
                setBits += (xorOfNums & 1);
                xorOfNums >>= 1;
            }
            
            return setBits;
            
        }
    }
    

Log in to reply
 

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