Preview:
class Solution {
public:
    vector<vector<int>> ans;
    
    void dfs(int curr, int dest, vector<vector<int>>& graph, vector<int> &path)
    {
        path.push_back(curr);
        if(curr==dest)
        {
            ans.push_back(path);
        }
        else
        {
            for(auto x:graph[curr])
            {
                dfs(x, dest, graph, path);
            }
        }
        path.pop_back();
    }
    
    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        int n=graph.size()-1;
        
        vector<int> path;
        dfs(0, n, graph, path);
        return ans;
    }
};
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter