class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
result = []
ans = []
def dfs(i):
if i == len(graph) - 1:
result.append(ans[:])
return
for j in graph[i]:
ans.append(j)
dfs(j)
ans.pop()
ans = [0]
dfs(0)
return result
07-24
960
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-24
1516
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)