797. All Paths From Source to Target
797. All Paths From Source to Target
class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
dest = len(graph) - 1
res = []
def dfs(k, curr):
if k == dest:
curr.append(k)
res.append(curr[::])
return
curr.append(k)
for node in graph[k]:
dfs(node, curr)
curr.pop()
dfs(0, [])
return res