Skip to content

[pull] master from JiayangWu:master #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
2021-08-24
  • Loading branch information
JiayangWu committed Aug 25, 2021
commit 0b8b9a0fb371f1816fdf5fbfb8f59f40a97d7618
16 changes: 9 additions & 7 deletions 0797.所有可能的路径/0797-所有可能的路径.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ def allPathsSourceTarget(self, graph):
:rtype: List[List[int]]
"""
n = len(graph)
visited = set()
def dfs(cur_node, path):
if cur_node == n - 1:
res = []
def dfs(cur, path):
path.append(cur)
if cur == n - 1:
res.append(path[:])
return
for next_node in graph[cur_node]:
dfs(next_node, path + [next_node])
res = []
dfs(0, [0])

for nxt in graph[cur]:
dfs(nxt, path[:])

dfs(0, [])
return res