nikunjsoni

797

Apr 22nd, 2021
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. class Solution {
  2. vector<vector<int>> ans;
  3. vector<int> path;
  4.    
  5. public:
  6.     vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
  7.         dfs(0, graph);
  8.         return ans;
  9.     }
  10.    
  11.     void dfs(int node, vector<vector<int>> &graph){
  12.         path.push_back(node);
  13.         if(node == graph.size()-1)
  14.             ans.push_back(path);
  15.         else
  16.             for(int child: graph[node])
  17.                 dfs(child, graph);
  18.         path.pop_back();
  19.     }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment