-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0797.cpp
More file actions
22 lines (22 loc) · 722 Bytes
/
0797.cpp
File metadata and controls
22 lines (22 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution {
void pushPaths(vector<vector<int>> &paths, vector<vector<int>> const &graph, int startNode, vector<int> currentPath) {
if (startNode == graph.size() - 1) {
paths.push_back(currentPath);
return;
}
if (graph[startNode].empty()) {
return;
}
for (int neighbor : graph[startNode]) {
currentPath.push_back(neighbor);
pushPaths(paths, graph, neighbor, currentPath);
currentPath.pop_back();
}
}
public:
vector<vector<int>> allPathsSourceTarget(vector<vector<int>> &graph) {
vector<vector<int>> paths;
pushPaths(paths, graph, 0, {0});
return paths;
}
};