deno.land / x / masx200_leetcode_test@10.6.5 / all-paths-from-source-to-target / index.ts
12345678910111213141516171819202122export default function allPathsSourceTarget(graph: number[][]): number[][] { const res: number[][] = []; dfs(graph, res, 0, [0]); return res;}function dfs( graph: number[][], res: number[][], index: number, path: number[],) { if (index === graph.length - 1) { res.push(Array.from(path)); return; } for (const next of graph[index]) { path.push(next); dfs(graph, res, next, path); path.pop(); }}
Version Info