Skip to content

Commit 1755a3c

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

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

191-number-of-1-bits.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
* @return {number}
44
*/
55
const hammingWeight = function(n) {
6-
let str = (n >>> 0).toString(2)
7-
let count = 0
8-
for(let i = 0; i < str.length; i++) {
9-
if(str.charAt(i) === '1') {
10-
count += 1
11-
}
12-
}
13-
return count
6+
const str = (n >>> 0).toString(2)
7+
let res = 0
8+
for(let c of str) {
9+
if(c === '1') res++
10+
}
11+
return res
1412
};

0 commit comments

Comments
 (0)