赞
踩
- func allPathsSourceTarget(graph [][]int) [][]int {
- n:=len(graph)
- ans:=[][]int{}
- path:=[]int{0}
- var dfs func()
- dfs=func() {
- if path[len(path)-1]==n-1 {
- ans=append(ans,append([]int{},path...))
- return
- }
- for _,site:=range graph[path[len(path)-1]] {
- path=append(path,site)
- dfs()
- path=path[:len(path)-1]
- }
- }
- dfs()
- return ans
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。