Skip to main content

🟡 剑指 Offer II 110. 所有路径

LeetCode 提示

题目难度 中等

原题链接 🔗 leetcode

题解 1.py#

class Solution:    def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:        n = len(graph)-1        res = []
        def dfs(cur: int):            path.append(cur)            if cur == n:                res.append(list(path))            else:                            curNexts = graph[cur]                for nxt in curNexts:                    dfs(nxt)
            path.pop()                path = []
        dfs(0)
        return res