FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/keys-and-rooms.py at master · Addoile/LeetCode-Solutions · GitHub
Addoile
LeetCode-Solutions
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
keys-and-rooms.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (19 loc) · 549 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
keys-and-rooms.py
Copy path
File metadata and controls
21 lines (19 loc) · 549 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Time: O(n!)
# Space: O(n)
class
Solution
(
object
):
def
canVisitAllRooms
(
self
,
rooms
):
"""
:type rooms: List[List[int]]
:rtype: bool
"""
lookup
=
set
([
0
])
stack
=
[
0
]
while
stack
:
node
=
stack
.
pop
()
for
nei
in
rooms
[
node
]:
if
nei
not
in
lookup
:
lookup
.
add
(
nei
)
if
len
(
lookup
)
==
len
(
rooms
):
return
True
stack
.
append
(
nei
)
return
len
(
lookup
)
==
len
(
rooms
)
Back
|
FazBrowse Home
|
New Git URL