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 a2abe12 commit 67ccb1aCopy full SHA for 67ccb1a
1 file changed
counting-bits/reeseo3o.js
@@ -0,0 +1,12 @@
1
+// Time Complexity: O(n)
2
+// Space Complexity: O(n)
3
+
4
+const countBits = (n) => {
5
+ const ans = new Array(n + 1).fill(0);
6
7
+ for (let i = 1; i <= n; i++) {
8
+ ans[i] = ans[i >> 1] + (i & 1);
9
+ }
10
11
+ return ans;
12
+};
0 commit comments