diff --git a/counting-bits/reeseo3o.js b/counting-bits/reeseo3o.js new file mode 100644 index 0000000000..14006e50d2 --- /dev/null +++ b/counting-bits/reeseo3o.js @@ -0,0 +1,12 @@ +// Time Complexity: O(n) +// Space Complexity: O(n) + +const countBits = (n) => { + const ans = new Array(n + 1).fill(0); + + for (let i = 1; i <= n; i++) { + ans[i] = ans[i >> 1] + (i & 1); + } + + return ans; +};