Leetcode 797. All Paths From Source to Target | | Leetcode 797. All Paths From Source to Target 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution1234567891011121314151617181920212223class Solution {public: vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) { vector<vector<int>> paths; vector<int> path; tranversePath(graph, paths, path, 0, graph.size() - 1); return paths; } void tranversePath(const vector<vector<int>>& graph, vector<vector<int>>& paths, vector<int> path, int current, int target) { path.push_back(current); int length = graph.size(); if(current == target) { paths.push_back(path); return; } for(int i = 0; i < graph[current].size(); i++) { tranversePath(graph, paths, path, graph[current][i], target); } }}; Reference https://leetcode.com/problems/all-paths-from-source-to-target/description/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏