Skip to content

Commit 5bb151f

Browse files
authored
797. All Paths From Source to Target
1 parent 2ae2e39 commit 5bb151f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

DFS/allPathsSourceTarget.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/**
2+
Given a directed acyclic graph (DAG) of n nodes labeled from 0 to n - 1, find all possible paths from node 0 to node n - 1 and return them in any order.
3+
4+
The graph is given as follows: graph[i] is a list of all nodes you can visit from node i (i.e., there is a directed edge from node i to node graph[i][j]).
5+
6+
7+
8+
Example 1:
9+
10+
Input: graph = [[1,2],[3],[3],[]]
11+
Output: [[0,1,3],[0,2,3]]
12+
Explanation: There are two paths: 0 -> 1 -> 3 and 0 -> 2 -> 3.
13+
14+
Example 2:
15+
16+
Input: graph = [[4,3,1],[3,2,4],[3],[4],[]]
17+
Output: [[0,4],[0,3,4],[0,1,3,4],[0,1,2,3,4],[0,1,4]]
18+
**/
19+
20+
121
class Solution {
222
private:
323
vector<vector<int>> res;

0 commit comments

Comments
 (0)