Super simple JS solution


  • 0
    J
    var hammingWeight = function(n) {
    n = n.toString(2);
    var result = 0;
    for (var i in n) {
        if (n[i] == '1') {
            result++;
        }
    }
    return result;
    

    };


Log in to reply
 

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