트리를 레벨별로 출력하라는 문제. 예를 들어, Root 가 1이고, 좌우 Child가 2, 3, 그 다음 세대가 각각 4/5, 6/7인 경우에는 -> [[1],[2,3],[4,5,6,7]] 처럼 출력하는 문제이다.이건 레이어가 중요한 문제BFS의 경우에 어떤 경우는 queue에 자식노드를 계속 추가하면서 while로 해서 다 방문하고, 지금 경우는 for 로 딱 현재 queue 길이만큼만 방문하되 자식 노드는 추가는 계속 해 나가기도 한다. 후자의 경우는 레벨별로 방문해야 하거나, 아니면 최단거리 문제를 풀어야 할 때 꼭 지켜줘야 하는 것이다. 아래 코드에 설명을 달아 둔다.from collections import dequeclass Solution: def levelOrder(self, root..
한 점(node 1)에서 시작하여 연결된 노드를 방문할 때 방문이 되지 않는 점을 찾는 것을 하고자 한다. 문제는 다음에서 가져왔다. https://open.kattis.com/problems/wheresmyinternet Where's My Internet?? – Kattis, Kattis Photo by Jerry John from Flickr A new town is being built far out in the country, and currently there are $N$ houses. People have already started moving in. However, some of the houses aren’t connected to the internet yet, and natural..
BST BST는 node.left.data > t = bintrees.RBTree([(3, 'Ryan'), (2, 'Muzi'), (5, 'Jay-Z'), (1, 'Chunshik')]) >>> t[2] 'Muzi' >>> t.min_item() (1, 'Chunshik') >>> t.max_item() (5, 'Jay-Z') >>> t.insert(8, 'Pengsoo') >>> t RBTree({1: 'Chunshik', 2: 'Muzi', 3: 'Ryan', 5: 'Jay-Z', 8: 'Pengsoo'}) >>> t.discard(5) >>> a = t.pop_min() >>> a (1, 'Chunshik') >>> b = t.pop_max() >>> b (8, 'Pengsoo') >>> t RBT..
- Total
- Today
- Yesterday
- 합격
- 카카오
- 동전문제
- BFS
- 입출력
- 개발자 채용
- 공부법
- 엔지니어
- dp
- 프림
- memoization
- connected components
- 다이내믹 프로그래밍
- Kosaraju
- iterable
- graph
- 코테
- dfs
- coupon collectors' problem
- 빅테크
- Union-find
- lru_cache
- OJ
- RTE
- 문자열
- bintrees
- nqueens
- deque
- python
- cache
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |