Leetcode 871 Solution
This article provides solution to leetcode question 871 (keys-and-rooms)
Access this page by simply typing in "lcs 871" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/keys-and-rooms
Solution
class Solution:
def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
q = []
q.append(0)
seen = set()
seen.add(0)
while q:
i = q.pop(0)
for nei in rooms[i]:
if nei not in seen:
q.append(nei)
seen.add(nei)
return len(seen) == len(rooms)