Skip to content

Commit 67ccb1a

Browse files
authored
[reeseo3o] WEEK 14 solutions (#2630)
* week13: meeting-rooms * week14: counting-bits
1 parent a2abe12 commit 67ccb1a

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

counting-bits/reeseo3o.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)