赞
踩
- 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);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。