File tree Expand file tree Collapse file tree 5 files changed +112
-0
lines changed
binary-tree-level-order-traversal Expand file tree Collapse file tree 5 files changed +112
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ [문제풀이]
3+ # Inputs
4+
5+ # Outputs
6+
7+ # Constraints
8+
9+ # Ideas
10+
11+ [회고]
12+
13+ """
14+
15+
Original file line number Diff line number Diff line change 1+ """
2+ [문제풀이]
3+ # Inputs
4+ n: int
5+ # Outputs
6+
7+ ans: arr
8+ 길이: n + 1
9+
10+ ans내 각 원소들 : ans[i]: i의 이진법에서 1의 개수
11+
12+ # Constraints
13+ 0 <= n <= 10^5
14+
15+ # Ideas
16+ 2중 for문 이면 안됨
17+
18+ [회고]
19+ dp를 활용한 풀이도 같이 알아두자
20+ """
21+
22+ # 내 풀이
23+ class Solution :
24+ def countBits (self , n : int ) -> List [int ]:
25+
26+ ans = []
27+
28+ for i in range (n + 1 ):
29+ if i == 0 or i == 1 :
30+ ans .append (i )
31+ continue
32+
33+ num = i
34+ cnt = 0
35+ while num > 0 :
36+ num , n = num // 2 , num % 2
37+ if n == 1 :
38+ cnt += 1
39+
40+ ans .append (cnt )
41+
42+ return ans
43+
44+ # 해설
45+ class Solution :
46+ def countBits (self , n : int ) -> List [int ]:
47+ dp = [0 ] * (n + 1 )
48+ for num in range (1 , n + 1 ):
49+ dp [num ] = dp [num // 2 ] + (num % 2 )
50+ return dp
51+
52+
Original file line number Diff line number Diff line change 1+ """
2+ [문제풀이]
3+ # Inputs
4+
5+ # Outputs
6+
7+ # Constraints
8+
9+ # Ideas
10+
11+ [회고]
12+
13+ """
14+
15+
Original file line number Diff line number Diff line change 1+ """
2+ [문제풀이]
3+ # Inputs
4+
5+ # Outputs
6+
7+ # Constraints
8+
9+ # Ideas
10+
11+ [회고]
12+
13+ """
14+
15+
Original file line number Diff line number Diff line change 1+ """
2+ [문제풀이]
3+ # Inputs
4+
5+ # Outputs
6+
7+ # Constraints
8+
9+ # Ideas
10+
11+ [회고]
12+
13+ """
14+
15+
You can’t perform that action at this time.
0 commit comments