Description
Submission
class Solution { vector<vector<int>> rets; int n; void dfs(int node, vector<int>& cur, vector<vector<int>>& graph) { if(node == n - 1) { rets.push_back(cur); return; } for(auto x: graph[node]) { cur.push_back(x); dfs(x, cur, graph); cur.pop_back(); } } public: vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) { n = graph.size(); vector<int> cur{0}; dfs(0, cur, graph); return rets; } };