4 Star 13 Fork 10

ShirDon-廖显东/零基础Go语言算法实战源码

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
interview6-4.go 871 Bytes
一键复制 编辑 原始数据 按行查看 历史
ShirDon-廖显东 提交于 2024-04-22 14:56 +08:00 . first commit
// ++++++++++++++++++++++++++++++++++++++++
// 《零基础Go语言算法实战》源码
// ++++++++++++++++++++++++++++++++++++++++
// Author:廖显东(ShirDon)
// Blog:https://www.shirdon.com/
// Gitee:https://gitee.com/shirdonl/goAlgorithms.git
// Buy link :https://item.jd.com/14101229.html
// ++++++++++++++++++++++++++++++++++++++++
package main
import "fmt"
func visitAllRooms(array [][]int) bool {
visited := make([]bool, len(array))
dfs(0, array, visited)
ret := true
for _, v := range visited {
ret = ret && v
}
return ret
}
func dfs(index int, array [][]int, visited []bool) {
if visited[index] {
return
}
visited[index] = true
for _, v := range array[index] {
dfs(v, array, visited)
}
}
func main() {
array := [][]int{{1, 3}, {3, 0, 1}, {2}, {0}}
res := visitAllRooms(array)
fmt.Println(res)
}
//$ go run interview5-4.go
//false
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/shirdonl/goAlgorithms.git
git@gitee.com:shirdonl/goAlgorithms.git
shirdonl
goAlgorithms
零基础Go语言算法实战源码
3e77a12194dd

搜索帮助