Created
May 30, 2023 14:44
-
-
Save Desolve/edc9788f87792c4c6dc14a112f7ee51a to your computer and use it in GitHub Desktop.
0797 All Paths From Source to Target
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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