98.所有可达路径
class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
ans = []
stack = []
n = len(graph)
def dfs(i):
if i == n - 1:
ans.append(stack[:])
for path in graph[i]:
stack.append(path)
dfs(path)
stack.pop()
stack.append(0)
dfs(0)
return ans