We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 66bab99 commit 493085fCopy full SHA for 493085f
797/797.cpp
@@ -0,0 +1,32 @@
1
+class Solution {
2
+public:
3
+ vector<vector<int>> dfs(vector<vector<int>>& adj, int x, int n) {
4
+ // base
5
+ if (x == n - 1) {
6
+ return {{x}};
7
+ }
8
+
9
+ // main
10
+ vector<vector<int>> ans;
11
+ for (auto v : adj[x]) {
12
+ // x -> v
13
+ vector<vector<int>> paths = dfs(adj, v, n);
14
+ for (auto subpath : paths) {
15
+ subpath.push_back(x);
16
+ ans.push_back(subpath);
17
18
19
20
+ return ans;
21
22
23
+ vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
24
+ int n = graph.size();
25
+ vector<vector<int>> paths = dfs(graph, 0, n);
26
27
+ for(auto& path: paths){
28
+ reverse(path.begin(), path.end());
29
30
+ return paths;
31
32
+};
0 commit comments