mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-14 07:51:14 +08:00
规范格式
This commit is contained in:
18
leetcode/0841.Keys-and-Rooms/841. Keys and Rooms.go
Normal file
18
leetcode/0841.Keys-and-Rooms/841. Keys and Rooms.go
Normal file
@ -0,0 +1,18 @@
|
||||
package leetcode
|
||||
|
||||
func canVisitAllRooms(rooms [][]int) bool {
|
||||
visited := make(map[int]bool)
|
||||
visited[0] = true
|
||||
dfsVisitAllRooms(rooms, visited, 0)
|
||||
return len(rooms) == len(visited)
|
||||
}
|
||||
|
||||
func dfsVisitAllRooms(es [][]int, visited map[int]bool, from int) {
|
||||
for _, to := range es[from] {
|
||||
if visited[to] {
|
||||
continue
|
||||
}
|
||||
visited[to] = true
|
||||
dfsVisitAllRooms(es, visited, to)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user