Intuitive Javascript Solution


  • 0
    D
    var hammingWeight = function(n) {
        // remove 0s from base2 representation of the number
        return n.toString(2).replace(/0/g, '').length;
    };
    

Log in to reply
 

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