Skip to content

Commit 0b8b9a0

Browse files
committedAug 25, 2021
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

+9-7
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)