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 2ee7477 commit 0a47b12Copy full SHA for 0a47b12
DFS/traditionalDFS/841.md
@@ -0,0 +1,33 @@
1
+## Keys and Rooms
2
+
3
+#### Description
4
5
+[link](https://leetcode.com/problems/keys-and-rooms/)
6
7
+---
8
9
+#### Solution
10
11
+- See Code
12
13
14
15
+#### Code
16
17
+> 最坏情况:O(n^2)
18
19
+```python
20
+class Solution:
21
+ def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
22
+ seen = set([0])
23
+ N = len(rooms)
24
+ state = [0]
25
+ while state:
26
+ r = state.pop()
27
+ for i in rooms[r]:
28
+ if i not in seen:
29
+ state.append(i)
30
+ seen.add(i)
31
+ if len(seen) == N: return True
32
+ return False
33
+```
0 commit comments