Skip to content

Commit 4e39c51

Browse files
committed
counting bits solution
1 parent e10ec05 commit 4e39c51

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

counting-bits/limlimjo.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// 시간복잡도: O(n log n)
2+
// 공간복잡도: O(n)
3+
4+
/**
5+
* @param {number} n
6+
* @return {number[]}
7+
*/
8+
var countBits = function(n) {
9+
let result = [];
10+
for (let i=0; i<=n; i++) {
11+
result.push(i.toString(2).replace(/0/g, '').length);
12+
}
13+
14+
return result;
15+
};

0 commit comments

Comments
 (0)