191. Number of 1 Bits
202401192310
tags: #bit-manipulation
var hammingWeight = function(n) {
let res = 0;
while (n) {
const bit = n & 1;
if (bit === 1) {
res += 1;
}
n >>>= 1;
}
return res;
};
202401192310
tags: #bit-manipulation
var hammingWeight = function(n) {
let res = 0;
while (n) {
const bit = n & 1;
if (bit === 1) {
res += 1;
}
n >>>= 1;
}
return res;
};