Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/edc9788f87792c4c6dc14a112f7ee51a to your computer and use it in GitHub Desktop.
Save Desolve/edc9788f87792c4c6dc14a112f7ee51a to your computer and use it in GitHub Desktop.
0797 All Paths From Source to Target
class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
def dfs(i, path):
if i == len(graph) - 1: res.append(path)
else:
for nxt in graph[i]: dfs(nxt, path + [nxt])
res = []
dfs(0, [0])
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment