Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 19, 2023
1 parent bfa6e4b commit 954dc48
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions leetcode/leetcode75/Graphs-DFS/841.KeysAndRooms/keysAndRooms.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"fmt"
)

func canVisitAllRooms(rooms [][]int) bool {
vis := make(map[int]bool)
var dfs func(u int)
dfs = func(u int) {
if vis[u] {
return
}
vis[u] = true
for _, v := range rooms[u] {
dfs(v)
}
}
dfs(0)
return len(vis) == len(rooms)
}

func main() {
rooms := [][]int{{1}, {2}, {3}, {}}
fmt.Println(canVisitAllRooms(rooms))
}

0 comments on commit 954dc48

Please sign in to comment.