Number of 1 Bits LeetCode solution in JavaScript

1
var hammingWeight = function (n) {
2
let count = 0,
3
i = 0;
4
while (n > 0) {
5
i = 0;
6
while (n >= Math.pow(2, i)) {
7
i++;
8
}
9
count++;
10
n -= Math.pow(2, i - 1);
11
}
12
return count;
13
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0