class Solution(object):
def allPathsSourceTarget(self, graph):
"""
:type graph: List[List[int]]
:rtype: List[List[int]]
"""
res = []
tar = len(graph)-1
def dfs(start, path):
if start == tar:
res.append(path)
for node in graph[start]:
dfs(node, path+[node])
dfs(0, [0])
return res
LeetCode 797. 所有可能的路径 python3 100%?
最新推荐文章于 2022-08-10 18:26:09 发布