当前位置:网站首页>Leetcode 797: all possible paths
Leetcode 797: all possible paths
2022-06-23 05:35:00 【Swarford】
subject :
Java Realization :
class Solution {
List<List<Integer>> r=new LinkedList<>();
public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
//graph Adjacency table , Each element is an array , There are other vertices connected to this vertex
LinkedList<Integer> path=new LinkedList<>(); // polymorphic ,LinkedList Only then removerLast() Method !
traverse(graph,0,path);
return r;
}
void traverse(int[][]graph,int s,LinkedList<Integer> path){
path.add(s); // Add start node first
// Determine whether the iteration has come to an end , If yes, complete a path
int n=graph.length;
if(s==n-1){
r.add(new LinkedList<>(path));
path.removeLast();// Recursion completes , remove path Medium element ,
return;
}
//dfs
for(int k :graph[s]){
traverse(graph,k,path);
}
path.removeLast(); // Recursion completes , remove path Medium element ,
}
}
边栏推荐
猜你喜欢

人脸识别 确定阈值

STC 32比特8051單片機開發實例教程 一 開發環境搭建

JVM原理之内存模型

The tiobe programming language ranking is an indicator of the popular trend of programming languages

STC 32位8051单片机开发实例教程 一 开发环境搭建
![[microservices | Nacos] Nacos realizes data isolation of multi environment and multi tenant](/img/dc/f00a780e96032c0b7d9b6d7c2267d1.png)
[microservices | Nacos] Nacos realizes data isolation of multi environment and multi tenant

JDBC introductory learning (II) encapsulation tool class

Seata四大模式之XA模式详解及代码实现

电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办

STC 32 Bit 8051 Single Chip Computer Development Example Tutorial one development environment
随机推荐
Export PDF with watermark
IDEA 代码开发完毕后,提交代码,提交后发现分支不对,怎么撤回
电脑开机显示器黑屏是什么原因,电脑显示器黑屏怎么办
Drama asking Huamen restaurant Weng
Software project management 8.4 Software project quality plan
Go language -panic and recover
MCS:离散随机变量
JVM原理之内存模型
Win11不能录制音频怎么办?Win11无法录入声音的解决方法
Go language - use of packages
MCS: discrete random variable Bernoulli distribution
Jenkins installs and deploys and automatically builds and publishes jar applications
MySQL自定义序列数的实现
MCS:连续随机变量——LogNormal分布
Go grouping & sorting
MCS:离散随机变量——Bernoulli分布
LeetCode-1757. Recyclable and low-fat products_ SQL
Un processus GC complet pour le principe JVM
About dos/ddos attack and defense
MCS: discrete random variable - uniform distribution