Javascript use bit operate >>>


  • 0
    B
    var hammingWeight = function(n) {
        var count = 0;
        
        while(n !== 0) {
            if (n & 1 > 0)
                count++;
            
            n = n >>> 1;
        }
        
        return count;
    };

Log in to reply
 

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