Skip to content

Commit 02e02e5

Browse files
committed
counting-bits solution (ts)
1 parent 8940ac5 commit 02e02e5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

counting-bits/hi-rachel.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function countBits(n: number): number[] {
2+
const result: number[] = new Array(n + 1).fill(0);
3+
4+
for (let i = 0; i <= n; i++) {
5+
result[i] = result[i >> 1] + (i & 1);
6+
}
7+
return result;
8+
}

0 commit comments

Comments
 (0)