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 cf7dbbe commit e113687Copy full SHA for e113687
โcounting-bits/soobing.tsโ
@@ -0,0 +1,15 @@
1
+/**
2
+ * ๋ฌธ์ ์ค๋ช
3
+ * - 0๋ถํฐ n๊น์ง์ ๋ชจ๋ ์์ ๋ํด ์ด์ง์์์ 1์ ๊ฐ์๋ฅผ ์ธ๋ ํจ์๋ฅผ ์์ฑํ๋ผ.
4
+ *
5
+ * ์์ด๋์ด
6
+ * 1) DP + ๋นํธ์ฐ์ฐ
7
+ * - ans[i] = ans[i >> 1] + (i & 1)
8
+ */
9
+function countBits(n: number): number[] {
10
+ const ans = Array(n + 1).fill(0);
11
+ for (let i = 1; i <= n; i++) {
12
+ ans[i] = ans[i >> 1] + (i & 1);
13
+ }
14
+ return ans;
15
+}
0 commit comments