1-Line JavaScript Code


  • 0
    Z

    /**

    • @param {number} n - a positive integer
    • @return {number}
      */
      var hammingWeight = function(n) {
      return n.toString(2).split('').map(a => parseInt(a)).reduce((a, b) => (a + b));
      };

Log in to reply
 

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