leetcode 797 所有可能的路径
LeetCode 所有 路径 可能
2023-09-27 14:29:24 时间
所有可能的路径
class Solution {
public:
vector<vector<int>> result;
vector<int> path;
void dfs(vector<vector<int>>& graph , int indnx)
{
if(indnx == graph.size()-1)
{
path.push_back(graph.size()-1);
result.push_back(path);
path.pop_back();
return;
}
for(int i=0 ; i<graph[indnx].size() ;i++)
{
path.push_back(indnx);
dfs(graph,graph[indnx][i]);
path.pop_back();
}
return;
}
vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
dfs(graph,0);
return result;
}
};
相关文章
- Leetcode: Heaters
- Leetcode: Recover Binary Search Tree
- Leetcode: N-Queens
- leetcode_Multiply Strings
- LeetCode高频题:一棵树的第i个节点的权重ai定义为:从根节到该节点的路径上,红色节点和蓝色节点的数量之差,求所有节点的权值之和
- LeetCode高频题:dfs排列组合问题,剪枝策略,参观展厅总时间120分钟,请你给出所有可能的参观方案的个数
- LeetCode高频题76. 最小覆盖子串:欠账还债还款问题,子串考虑i开头的情况所有答案更新一波
- LeetCode高频题56. 合并区间,将重叠的区间合并为一个区间,包含所有区间
- JS leetcode 找到所有数组中消失的数字 题解分析
- [LeetCode] Merge k Sorted Lists
- [LeetCode] Word Break
- leetcode Word Break I II 算法分析
- 【LeetCode】338. Counting Bits (2 solutions)
- 【LeetCode】114. Flatten Binary Tree to Linked List
- 【LeetCode】88. Merge Sorted Array (2 solutions)
- [LeetCode] 1057. Campus Bikes 校园自行车
- [LeetCode] 438. Find All Anagrams in a String 找出字符串中所有的变位词
- [LeetCode] Find the Difference 寻找不同
- [LeetCode] 89. Gray Code 格雷码
- leetcode 257. Binary Tree Paths 二叉树的所有路径(简单)