Skip to content

Commit 6547750

Browse files
committed
solve: counting bits
1 parent e6007ae commit 6547750

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

counting-bits/tolluset.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* TC: O(nlogn)
3+
* SC: O(nlogn)
4+
* */
5+
function countBits(n: number): number[] {
6+
return Array.from({ length: n + 1 }, (_, i) => i).map(
7+
(v) =>
8+
v
9+
.toString(2)
10+
.split("")
11+
.filter((v) => v === "1").length,
12+
);
13+
}

0 commit comments

Comments
 (0)