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 c6d37af commit 71307c3Copy full SHA for 71307c3
counting-bits/gitsunmin.ts
@@ -0,0 +1,10 @@
1
+/**
2
+ * https://leetcode.com/problems/counting-bits/
3
+ * time complexity : O(n)
4
+ * space complexity : O(n)
5
+ */
6
+function countBits(n: number): number[] {
7
+ const arr = new Array(n + 1).fill(0);
8
+ for (let i = 1; i <= n; i++) arr[i] = arr[i >> 1] + (i & 1);
9
+ return arr;
10
+}
0 commit comments