Skip to content

Commit 1ae4b2c

Browse files
authored
solution on counting-bits
1 parent 1387991 commit 1ae4b2c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

counting-bits/Lustellz.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Runtime: 6mx
2+
// Memory: 61.10MB
3+
4+
function countBits(n: number): number[] {
5+
let answer: number[] = Array(n + 1).fill(0);
6+
7+
for(let i = 1 ; i <= n ; i++){
8+
let tmp = i;
9+
while (tmp > 0){
10+
answer[i] += tmp % 2
11+
tmp = Math.floor(tmp / 2)
12+
}
13+
}
14+
15+
return answer;
16+
};

0 commit comments

Comments
 (0)