题解 | #求最大连续bit数#
求最大连续bit数
https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2
主要考察位运算 通过 ‘&’ 以及 有符号右移‘>>’解决 完整代码如下:
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(line = await readline()){
let n = parseInt(line);
let max = 0;
let count = 0;
while (n > 0) {
if ((n & 1) === 0) {
count = 0;
}
else {
count += 1;
}
max = Math.max(max, count);
n >>= 1;
}
console.log(max);
}
}()


滴滴公司福利 1726人发布