题解 | #查找输入整数二进制中1的个数#

查找输入整数二进制中1的个数

https://www.nowcoder.com/practice/1b46eb4cf3fa49b9965ac3c2c1caf5ad

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(num = await readline()){
        console.log( parseInt(num).toString(2).replaceAll(/0+/g,'').length );
    }
}()

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务