Skip to content

Commit 862ff81

Browse files
committed
docs: add notes - Solution 2 (Invert binary tree) & SC (Course schecule)
1 parent b175e31 commit 862ff81

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

course-schedule/KwonNayeon.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
Time Complexity: O(N + P)
1010
- N: numCourses, P: prerequisites의 길이
1111
12-
Space Complexity: O(N + P)
12+
Space Complexity: O(N + P)
1313
- 세트의 메모리 사용량이 N과 비례하고 인접 리스트의 크기가 P
14+
- 재귀 호출 스택의 깊이는 최악의 경우 O(N)
1415
1516
풀이방법:
1617
1. prerequisites을 directed graph로 변환
1718
- 각 코스별로 선수과목의 리스트를 저장함
18-
1919
2. DFS를 사용하여 cycle 존재 여부 확인
2020
- visited 배열: 이미 확인이 완료된 노드 체크
2121
- path 배열: 현재 DFS 경로에서 방문한 노드 체크
22-
2322
3. cycle이 발견되면 false, 그렇지 않으면 true 반환
2423
- 현재 경로에서 이미 방문한 노드를 다시 만나면 cycle 있음
2524
- 모든 노드 방문이 가능하면 cycle 없음

invert-binary-tree/KwonNayeon.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,34 @@
33
- The number of nodes in the tree is in the range [0, 100].
44
- -100 <= Node.val <= 100
55
6-
Time Complexity:
7-
- O(n): 각 노드를 한 번씩 방문함
6+
<Solution 1>
7+
Time Complexity: O(n)
8+
- 각 노드를 한 번씩 방문함
89
9-
Space Complexity:
10-
- O(w): w는 트리의 최대 너비(width)
10+
Space Complexity: O(w)
11+
- w는 트리의 최대 너비(width)
1112
1213
풀이방법:
1314
1. 큐를 사용한 BFS(너비 우선 탐색)
1415
2. FIFO(First In First Out)로 노드를 처리함
1516
3. 각 노드를 방문할 때마다:
1617
- 왼쪽과 오른쪽 자식 노드의 위치를 교환
1718
- 교환된 자식 노드들을 큐에 추가하여 다음 노드를 처리함
18-
"""
1919
20+
<Solution 2>
21+
Time Complexity: O(n)
22+
- 각 노드를 한 번씩 방문함
23+
24+
Space Complexity: O(h)
25+
- h는 트리의 높이, 재귀 호출 스택의 최대 깊이
26+
27+
풀이방법:
28+
1. DFS(깊이 우선 탐색)와 재귀를 활용
29+
2. 각 노드에서:
30+
- 왼쪽과 오른쪽 자식 노드의 위치를 교환
31+
- 재귀적으로 왼쪽, 오른쪽 서브트리에 대해 같은 과정 반복
32+
3. Base case: root가 None이면 None 반환
33+
"""
2034
# Definition for a binary tree node.
2135
# class TreeNode:
2236
# def __init__(self, val=0, left=None, right=None):

merge-k-sorted-lists/KwonNayeon.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Constraints:
3+
- k == lists.length
4+
- 0 <= k <= 10^4
5+
- 0 <= lists[i].length <= 500
6+
- -10^4 <= lists[i][j] <= 10^4
7+
- lists[i] is sorted in ascending order.
8+
- The sum of lists[i].length will not exceed 10^4
9+
10+
Time Complexity:
11+
-
12+
13+
Space Complexity:
14+
-
15+
16+
풀이방법:
17+
1.
18+
"""

search-in-rotated-sorted-array/KwonNayeon.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616
1. Binary Search
1717
- left와 right 포인터로 탐색 범위 지정
1818
- mid가 target인지 먼저 확인
19-
2019
2. 정렬된 부분 찾기
2120
- mid를 기준으로 왼쪽이 정렬되어 있는지 확인
2221
- 정렬된 부분에서 target이 존재할 수 있는 범위를 파악
23-
2422
3. Target 위치 탐색
2523
- 왼쪽이 정렬되어 있고 target이 그 범위 안에 있다면 오른쪽 범위를 줄임
2624
- 그렇지 않다면 왼쪽 범위를 늘림
2725
- 반대의 경우도 동일한 방법 적용
28-
2926
4. Target을 찾지 못한 경우 -1을 반환함
3027
"""
3128
class Solution:

0 commit comments

Comments
 (0)