Skip to content

Commit feca8be

Browse files
committed
add: #232 Number of 1 Bits
1 parent 4e1d2b0 commit feca8be

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

number-of-1-bits/sukyoungshin.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function hammingWeight(n: number): number {
2+
let count = 0;
3+
let num = n;
4+
5+
while (num > 0) {
6+
if (num % 2 === 1) {
7+
count++;
8+
}
9+
num = Math.floor(num / 2);
10+
}
11+
12+
return count;
13+
};

0 commit comments

Comments
 (0)