MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / dfs

Method dfs

java/0797-all-paths-from-source-to-target.java:11–26  ·  view source on GitHub ↗
(
        List<List<Integer>> ans,
        int[][] graph,
        List<Integer> list,
        int i
    )

Source from the content-addressed store, hash-verified

9 }
10
11 public void dfs(
12 List<List<Integer>> ans,
13 int[][] graph,
14 List<Integer> list,
15 int i
16 ) {
17 if (i == graph.length - 1) {
18 ans.add(new ArrayList<Integer>(list));
19 return;
20 }
21 for (int val : graph[i]) {
22 list.add(val);
23 dfs(ans, graph, list, val);
24 list.remove(list.size() - 1);
25 }
26 }
27}

Callers 1

allPathsSourceTargetMethod · 0.95

Calls 3

addMethod · 0.45
removeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected