题目:
题解:
class Solution:def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:edges = collections.defaultdict(list)indeg = [0] * numCoursesfor info in prerequisites:edges[info[1]].append(info[0])indeg[info[0]] += 1q = collections.deque([u for u in range(numCourses) if indeg[u] == 0])visited = 0while q:visited += 1u = q.popleft()for v in edges[u]:indeg[v] -= 1if indeg[v] == 0:q.append(v)return visited == numCourses