We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b34e4aa commit f0ef403Copy full SHA for f0ef403
medium/keys-and-rooms/keys-and-rooms.py
@@ -0,0 +1,10 @@
1
+class Solution:
2
+ def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
3
+ keychain = {0}
4
+ def dfs(room_num):
5
+ for key in rooms[room_num]:
6
+ if key not in keychain:
7
+ keychain.add(key)
8
+ dfs(key)
9
+ dfs(0)
10
+ return len(keychain) == len(rooms)
0 commit comments