Hamming Distance Javascript without using toString(2)


  • 0
    N
    var hammingDistance = function(x, y) {
        
        
        let diff = 0;
        while (x/2>0 || y/2>0){
            if (x%2!=y%2){
                diff+=1;
            }
            
            x = Math.floor(x/2);
            y = Math.floor(y/2);
        }
        return diff;
        
        
    };
    

Log in to reply
 

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