File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * ๊ณต๊ฐ ๋ณต์ก๋: O(N)
3+ * ์๊ฐ ๋ณต์ก๋: O(N)
4+ * - ๋ง์ฝ 1 ~ N ๊น์ง ๊ฐ ์์ ๋ํด์ ์ด์ง์๋ก ๋ณํํ ๋ค 1์ ๊ฐ์๋ฅผ ์นด์ดํธ ํ๋ค๋ฉด? - O(NlogN)
5+ * Note:
6+ * - a >> b: a ์ ์ด์ง ํํ์ ์คํ์ชฝ์ผ๋ก b ๋นํธ๋งํผ ์ด๋
7+ * - i >> 1: a ์ ์ด์ง ํํ์์ ๊ฐ์ฅ ์คํ์ชฝ ํ๋๊ฐ ์๋ฆผ (i๋ ์์ ๋ฒ์๋ฅผ ๊ฐ์ง๋ฏ๋ก, ์ผ์ชฝ์ 0์ผ๋ก ์ฑ์์ง)
8+ * - a & b: AND ์ฐ์ฐ
9+ * - i & 1: ์ด์ ๊ฒฐ๊ณผ ๊ฐ์ด ๋ฉ๋ชจ๋์ด ์์ผ๋ฏ๋ก, ๋ด๊ฐ ๊ถ๊ธํ ๊ฒ ๊ฐ์ฅ ๋ง์ง๋ง ์๋ฆฌ ์ ๊ฐ์ด 1์ธ์ง ์ฌ๋ถ.
10+ */
11+ class Solution {
12+ public int [] countBits (int n ) {
13+ int [] result = new int [n + 1 ];
14+ for (int i = 1 ; i <= n ; i ++) {
15+ result [i ] = result [i >> 1 ] + (i & 1 );
16+ }
17+ return result ;
18+ }
19+ }
You canโt perform that action at this time.
0 commit comments