Medium
出度
True
False
以上,尝试写一下代码,AC!
python3
class Solution:
def canVisitAllRooms(self, rooms: List[List[int]]) -> bool:
visited = set()
def helper(curIndex):
visited.add(curIndex)
for n in rooms[curIndex]:
if n not in visited:
helper(n)
helper(0)
return len(visited) == len(rooms)