add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent 886b5e0a8e
commit 67cad91898
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
47 changed files with 1549 additions and 1 deletions

View file

@ -0,0 +1,23 @@
package q841
func canVisitAllRooms(rooms [][]int) bool {
locked := len(rooms) - 1
opened := make([]bool, len(rooms))
opened[0] = true
queue := []int{0}
for ; len(queue) > 0; queue = queue[1:] {
for _, i := range rooms[queue[0]] {
if opened[i] {
continue
}
opened[i] = true
locked--
queue = append(queue, i)
}
}
return locked == 0
}
var _ = canVisitAllRooms