(int graph[][], int element, List<List<Integer>> list,List<Integer> sublist)
| 1 | class Solution { |
| 2 | |
| 3 | public static void backTrack(int graph[][], int element, List<List<Integer>> list,List<Integer> sublist){ |
| 4 | // Base Case |
| 5 | if(element==graph.length-1) |
| 6 | { |
| 7 | list.add(new ArrayList<>(sublist)); |
| 8 | return; |
| 9 | } |
| 10 | |
| 11 | for(int i=0;i<graph[element].length;i++) |
| 12 | { |
| 13 | sublist.add(graph[element][i]); |
| 14 | backTrack(graph,graph[element][i],list,sublist); |
| 15 | sublist.remove(sublist.size()-1); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public List<List<Integer>> allPathsSourceTarget(int[][] graph) { |
| 20 | List<Integer> sublist = new ArrayList<Integer>(); |
no test coverage detected