输出有向无环图的所有路径

class Solution {
public:
    void findpath(vector<vector<int>>& graph,int start,int end,vector<int>& path,vector<vector<int>>& allpath){
        path.push_back(start);
        if(start==end){
            allpath.push_back(path);
        }
        for(int i=0;i<graph[start].size();i++){
            findpath(graph,graph[start][i],end,path,allpath);
        }
        path.pop_back();
    }
    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        vector<int> path;
        vector<vector<int>> allpath;
        findpath(graph,0,graph.size()-1,path,allpath);
        return allpath;
    }
};
上一篇:leetcode-785. 判断二分图


下一篇:3D引擎数据结构与glTF(2): Scene Graph