Skip to content

Commit f0ef403

Browse files
committed
Adding solution to challenge '841. Keys and Rooms' (medium).
1 parent b34e4aa commit f0ef403

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)