
문제 감 잡는 데 들이는 시간도 충분해야 한다.
r과 c를 이용해서 4방향으로 재귀탐색을 진행한다. dr과 dc를 재귀호출에서 +1, -1하거나 방향을 배열로 정의해놓고 방향의 개수만큼 반복문을 호출할 수 있다. ✅ DFS 쉬운 문제 추천 (LeetCode Easy)
Number of Islands
1로 연결된 섬을 모두 세는 DFS 대표 문제
🔗 https://leetcode.com/problems/number-of-islands/
Flood Fill
상하좌우로 연결된 같은 색 영역을 DFS로 색칠
🔗 https://leetcode.com/problems/flood-fill/
Max Area of Island
DFS로 연결된 섬 중 가장 큰 면적 구하기
🔗 https://leetcode.com/problems/max-area-of-island/
Path Sum
이진 트리에서 루트~리프 경로의 합이 target과 같은지
🔗 https://leetcode.com/problems/path-sum/
All Paths From Source to Target
DAG(방향성 비순환 그래프)에서 시작~도착까지 모든 경로 탐색
🔗 https://leetcode.com/problems/all-paths-from-source-to-target/
큐를 사용해서 레벨별로 가까운 노드부터 방문한다.
0
/ \
1 2
/ \
3 4
시작: queue = [0]
0 방문 → 1, 2 큐에 추가 → queue = [1, 2]
1 방문 → 3 큐에 추가 → queue = [2, 3]
2 방문 → 4 큐에 추가 → queue = [3, 4]
3 방문
4 방문
Matrix
🔗 https://leetcode.com/problems/01-matrix/
Rotting Oranges
🔗 https://leetcode.com/problems/rotting-oranges/
Shortest Path in Binary Matrix
🔗 https://leetcode.com/problems/shortest-path-in-binary-matrix/
Number of Islands
🔗 https://leetcode.com/problems/number-of-islands/
Nearest Exit from Entrance in Maze
🔗 https://leetcode.com/problems/nearest-exit-from-entrance-in-maze/