Skip to content

Commit

Permalink
Keys and Rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Dec 1, 2018
1 parent f43e962 commit c97f6dd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 841. Keys and Rooms
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from queue import Queue


class Solution:
def canVisitAllRooms(self, rooms):
"""
:type rooms: List[List[int]]
:rtype: bool
"""
s=set(rooms[0])
s.add(0)
q=Queue()
for k in rooms[0]:
q.put(k)
while not q.empty():
mask=q.get()
for k in rooms[mask]:
if k not in s:
s.add(k)
q.put(k)

return len(s)==len(rooms)

rooms=[[1,3],[3,0,1],[2],[0]]
sol=Solution()
print(sol.canVisitAllRooms(rooms))

0 comments on commit c97f6dd

Please sign in to comment.