当前位置:网站首页>leetcode797. All possible paths (medium)
leetcode797. All possible paths (medium)
2022-06-12 04:20:00 【Heavy garbage】



Ideas : acyclic -> dfs Find a path , Until arrival n - 1
Be careful : Memorize dfs( Save a node to n-1 The path of ) Not optimized , This is because structure ans Complexity and directness dfs The complexity is the same , It doesn't really optimize -> I have tried to write code , It was used Memorization is even slower ...
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;
}
};
边栏推荐
- 疫情数据分析平台工作报告【4】跨域相关
- webpack---优化_缓存
- Is it safe for Guojin Securities Commission Jinbao to open an account? How should we choose securities companies?
- DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode
- Dynamic gauge (15) - Minimum toll
- [Yugong series] March 2022 asp Net core Middleware - current limiting
- Street lighting IOT technology scheme, esp32-s3 chip communication application, intelligent WiFi remote control
- 疫情数据分析平台工作报告【2】接口API
- [fpga+gps receiver] detailed design introduction of dual frequency GPS receiver based on FPGA
- [Yugong series] March 2022 asp Net core Middleware - conditional routing
猜你喜欢

Ebpf series learning (4) learn about libbpf, co-re (compile once – run everywhere) | use go to develop ebpf programs (cloud native tool cilium ebpf)

Solution to missing in unity script

电商中台系统架构
![Work report of epidemic data analysis platform [6] visual drawing](/img/cc/9eaff451068d0efb174b58719c700e.png)
Work report of epidemic data analysis platform [6] visual drawing

Naive Bayes classification of scikit learn
![[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

2.28 (defect filling) data type conversion exception handling part multi threading

LINQ group by and select series - LINQ group by and select collection

DS18B20 digital thermometer (I) electrical characteristics, power supply and wiring mode

SQL safe backup display and zoom font support
随机推荐
R语言plotly可视化:plotly可视化基础二维直方图、自定义设置二维直方图的颜色、二维直方图是二元分布的直方图可视化(Basic 2D Histogram)
Introduction to distributed locks
Yyds dry inventory MySQL learning - how transactions are isolated
【clickhouse专栏】新建库角色用户初始化
mysqld: Can‘t create directory ‘D: oftinstall\mysql57 (Errcode: 2 - No such file or directory)
Smart Panel wifi Linkage Technology, esp32 wireless chip module, Internet of Things WiFi Communication Application
Illustrating the use of Apache skywalking UI
The solution to the error "xxx.pri has modification time XXXX s in the futrue" in the compilation of domestic Kirin QT
Legendary biological car-t has been approved by FDA, becoming the first domestic cell therapy product to successfully go to sea
What is the difference between FOB, CIF and CFR?
认真工作对自己到底意味着什么?
[软件工具][原创]voc数据集类别名批量修改工具使用教程
Kotlin协程协程作用域,CoroutineScope MainScope GlobalScope viewModelScope lifecycleScope 分别代表什么
如何制作数据集并基于yolov5训练成模型并部署
Solution en cas de défaillance du script Unity
eBPF系列学习(4)了解libbpf、CO-RE (Compile Once – Run Everywhe) | 使用go开发ebpf程序(云原生利器cilium ebpf )
R language write function: use the write function to write data to the rstudio console, and the write function to write data to a new rstudio window (start a new window)
智能面板WiFi联动技术,ESP32无线芯片模组,物联网WiFi通信应用
Smart panel WiFi linkage technology, esp32 wireless chip module, Internet of things WiFi communication application
Work report of epidemic data analysis platform [4] cross domain correlation