[LeetCode] All Paths From Source to Target

class Solution {
public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
List<List<Integer>> result = new ArrayList<>();
dfs(result, new ArrayList<>(), graph, 0, graph.length - 1);
return result;
}
public void dfs(List<List<Integer>> result, List<Integer> path, int[][] graph, int start, int end) {
path.add(start);
if (start == end) {
result.add(new ArrayList<>(path));
} else {
for (int node : graph[start]) {
dfs(result, path, graph, node, end);
}
}
path.remove(path.size() - 1);
}
}