All Paths From Source to Target LeetCode solution in Python

1
class Solution:
2
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
3
res = []
4
self.explore(graph, graph[0], [0], res)
5
return res
6

7
def explore(self, graph, candidates, step, res):
8
if step[-1] == len(graph) - 1:
9
res.append(list(step))
10
else:
11
for i in range(len(candidates)):
12
step.append(candidates[i])
13
self.explore(graph, graph[candidates[i]], step, res)
14
step.pop()

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0