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 6d43c39 commit 3855d02Copy full SHA for 3855d02
counting-bits/wogha95.js
@@ -0,0 +1,25 @@
1
+// TC: O(N)
2
+// SC: O(N)
3
+
4
+/**
5
+ * @param {number} n
6
+ * @return {number[]}
7
+ */
8
+var countBits = function (n) {
9
+ const result = [0];
10
+ let pointer = 0;
11
+ let lastPointer = 0;
12
13
+ for (let num = 1; num <= n; num++) {
14
+ result.push(result[pointer] + 1);
15
16
+ if (pointer === lastPointer) {
17
+ lastPointer = result.length - 1;
18
+ pointer = 0;
19
+ } else {
20
+ pointer += 1;
21
+ }
22
23
24
+ return result;
25
+};
0 commit comments