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 7eeb25e commit d77a90aCopy full SHA for d77a90a
841.Keys_and_Rooms/main.py
@@ -0,0 +1,28 @@
1
+class Solution:
2
+ def canVisitAllRooms(self, rooms):
3
+ """
4
+ :type rooms: List[List[int]]
5
+ :rtype: bool
6
7
+
8
+ locks = [1] + [0] * (len(rooms) - 1)
9
+ keys = set()
10
11
+ for key in rooms[0]:
12
+ keys.add(key)
13
+ found = True
14
15
+ while found:
16
+ found = False
17
+ for i in range(len(rooms)):
18
+ if locks[i] == 0:
19
+ if i in keys:
20
+ locks[i] = 1
21
+ for key in rooms[i]:
22
23
24
25
+ if 0 in locks:
26
+ return False
27
+ else:
28
+ return True
0 commit comments