当前位置:网站首页>leetcode797. 所有可能的路径(中等)
leetcode797. 所有可能的路径(中等)
2022-06-12 04:16:00 【重you小垃】



思路:无环 -> dfs找路径,直到到达n - 1
注意:记忆化dfs(保存某节点到n-1的路径)并不会优化,这是因为构造ans的复杂度和直接dfs的复杂度是一样的,并不会真正优化 ->自己尝试写过代码了, 用了记忆化甚至更慢了。。。
class Solution {
public:
vector<vector<int>> ans;
vector<int> path;
void dfs(vector<vector<int>>& graph, int index) {
int n = graph.size();
if (index == n - 1) ans.push_back(path);
for (auto& a : graph[index]) {
path.push_back(a);
dfs(graph, a);
path.pop_back();
}
}
vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
path.push_back(0);
dfs(graph, 0);
return ans;
}
};
边栏推荐
- Database selected 60 interview questions
- Implementation of fitness club management system based on SSH
- 【clickhouse专栏】新建库角色用户初始化
- Goodbye to excel and PPT, I found a better visual fool software
- php和js去掉所有空格
- 智能面板WiFi聯動技術,ESP32無線芯片模組,物聯網WiFi通信應用
- SqEL简单上手
- 疫情数据分析平台工作报告【42】CodeNet
- Absolute positioning three ways to center the box
- Construction case of Expressway Precast Beam Yard (with scheme text)
猜你喜欢

路灯照明物联网技术方案,ESP32-S3芯片通信应用,智能WiFi远程控制

WiFi module scheme of the wireless Internet of things, esp32-s3 chip technology, helps the equipment to be intelligent

Concept and introduction of microservice

怎样拥有心灵的平和?获得一颗全新的心灵

MySQL的check约束数字问题

E-commerce middle office system architecture
![[software tool] [original] tutorial on using VOC dataset class alias batch modification tool](/img/25/31d771c9770bb7f455f35e38672170.png)
[software tool] [original] tutorial on using VOC dataset class alias batch modification tool

Esp32c3 remote serial port

【C语言】程序的内存四区模型

Batch automated e-mail: Vika Vige table x Tencent Qianfan scene connector has made new moves, and business communication and event marketing only need 3 steps
随机推荐
What does kotlin collaboration scope and coroutinescope mainscope globalscope viewmodelscope lifecyclescope represent respectively
Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application
【C语言】程序的内存四区模型
Sqel easy to use
SQL Safe Backup显示器和缩放字体的支持
Kinematic gauge (14) - Triangle optimal path problem
Double objective learning materials sorting
2.28 (defect filling) data type conversion exception handling part multi threading
MongoDB精华总结
JSP implementation of bank counter business performance evaluation system
Successfully solved: warning: there was an error checking the latest version of pip
Notes on relevant knowledge points such as original code / inverse code / complement code, size end, etc
Brief introduction to 44 official cases of vrtk3.3 (combined with steamvr)
无线物联网WiFi模块方案,ESP32-S3芯片技术,助力设备智能化
R语言使用survival包的coxph函数构建cox回归模型、使用ggrisk包的ggrisk函数可视化Cox回归的风险评分图(风险得分图)、并解读风险评分图、基于LIRI数据集(基因数据集)
Ebpf series learning (4) learn about libbpf, co-re (compile once – run everywhere) | use go to develop ebpf programs (cloud native tool cilium ebpf)
LINQ group by and select series - LINQ group by and select collection
Construction case of Expressway Precast Beam Yard (with scheme text)
疫情数据分析平台工作报告【6】可视化绘图
Kotlin协程协程作用域,CoroutineScope MainScope GlobalScope viewModelScope lifecycleScope 分别代表什么