All Paths From Source to Target LeetCode solution in Python
1class Solution:2def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:3res = []4self.explore(graph, graph[0], [0], res)5return res67def explore(self, graph, candidates, step, res):8if step[-1] == len(graph) - 1:9res.append(list(step))10else:11for i in range(len(candidates)):12step.append(candidates[i])13self.explore(graph, graph[candidates[i]], step, res)14step.pop()