Участник:Plague rat/Keys and Rooms

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/keys-and-rooms/

class Solution:
    def DFSBypass(self, graph, start, visited):
        visited[start] = True
        for v in graph[start]:
            if not visited[v]:
                self.DFSBypass(graph, v, visited)
 
 
    def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
        visited = [False] * len(rooms)
        self.DFSBypass(rooms, 0, visited)
        return not False in visited