Graph Theory 문제 7번
https://leetcode.com/problems/all-paths-from-source-to-target/
DFS, Recursive
class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
result = []
def dfs(node, path):
if node == len(graph) - 1:
result.append(path[:])
return
for nei in graph[node]:
path.append(nei)
dfs(nei, path)
path.pop()
dfs(0, [0])
return result