Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- vector<vector<int>> ans;
- vector<int> path;
- public:
- vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
- dfs(0, graph);
- return ans;
- }
- void dfs(int node, vector<vector<int>> &graph){
- path.push_back(node);
- if(node == graph.size()-1)
- ans.push_back(path);
- else
- for(int child: graph[node])
- dfs(child, graph);
- path.pop_back();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment