Update 0797.所有可能的路径 Go写法

更新函数名为dfs
This commit is contained in:
Shixiaocaia
2023-08-30 11:35:06 +08:00
committed by GitHub
parent 076d87605e
commit 0bfd53394e

View File

@ -223,8 +223,8 @@ class Solution:
func allPathsSourceTarget(graph [][]int) [][]int {
result := make([][]int, 0)
var trace func(path []int, step int)
trace = func(path []int, step int){
var dfs func(path []int, step int)
dfs = func(path []int, step int){
// 从0遍历到length-1
if step == len(graph) - 1{
tmp := make([]int, len(path))
@ -235,11 +235,11 @@ func allPathsSourceTarget(graph [][]int) [][]int {
for i := 0; i < len(graph[step]); i++{
next := append(path, graph[step][i])
trace(next, graph[step][i])
dfs(next, graph[step][i])
}
}
// 从0开始开始push 0进去
trace([]int{0}, 0)
dfs([]int{0}, 0)
return result
}