We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 012343e commit bbead63Copy full SHA for bbead63
counting-bits/hyer0705.ts
@@ -0,0 +1,11 @@
1
+// Time Complexity: O(n)
2
+// Space Complexity: O(n)
3
+function countBits(n: number): number[] {
4
+ const ans: number[] = Array.from({ length: n + 1 }, () => 0);
5
+
6
+ for (let i = 1; i <= n; i++) {
7
+ ans[i] = ans[i >> 1] + (i & 1);
8
+ }
9
10
+ return ans;
11
+}
0 commit comments