Skip to content

Commit cae80b9

Browse files
authored
Update 191-number-of-1-bits.js
1 parent 1755a3c commit cae80b9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

191-number-of-1-bits.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* @param {number} n - a positive integer
3+
* @return {number}
4+
*/
5+
const hammingWeight = function(n) {
6+
let res = 0
7+
while(n > 0) {
8+
if(n & 1) res++
9+
n = n >>> 1
10+
}
11+
return res
12+
};
13+
14+
// another
15+
116
/**
217
* @param {number} n - a positive integer
318
* @return {number}

0 commit comments

Comments
 (0)