11. 二进制中1的个数
yangxiaolin opened this issue · comments
yangxiaolin commented
这个问题可以用一个取巧得方式实现。
function NumberOf1(n) {
return n.toString(2)
.split('')
.reduce((count, current) => current === '1' ? count + 1 : count, 0)
}
效率比你实现得差点