一、题目内容
二、代码
class Solution {
List<List<Integer>>list=new ArrayList<>();
List<Integer>templist=new ArrayList<>();
public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
dfs(graph,0,graph.length);
return list;
}
public void dfs(int [][]graph, int i,int n){
if(i==n-1)
{
templist.add(i);
list.add(new ArrayList<>(templist));
templist.remove(templist.size()-1);
return;
}
templist.add(i);
for(int a:graph[i]){
dfs(graph,a,n);
}
templist.remove(templist.size()-1);
}
}