Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b8b9a0

Browse files
2021年08月24日
1 parent f83f39d commit 0b8b9a0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

‎0797.所有可能的路径/0797-所有可能的路径.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ def allPathsSourceTarget(self, graph):
55
:rtype: List[List[int]]
66
"""
77
n = len(graph)
8-
visited = set()
9-
def dfs(cur_node, path):
10-
if cur_node == n - 1:
8+
res = []
9+
def dfs(cur, path):
10+
path.append(cur)
11+
if cur == n - 1:
1112
res.append(path[:])
1213
return
13-
for next_node in graph[cur_node]:
14-
dfs(next_node, path + [next_node])
15-
res = []
16-
dfs(0, [0])
14+
15+
for nxt in graph[cur]:
16+
dfs(nxt, path[:])
17+
18+
dfs(0, [])
1719
return res

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /