Problem · Canonical Warm-Up
mediumtopological-sort · cycle-detection · bfs · dfsTime · O(V + E)Space · O(V + E)
Course Schedule
Problem walkthrough: statement, hints, solution, mistakes
There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [a, b] indicates that you must take course b first to take course a.
Return true if you can finish all courses. Otherwise, return false.
Constraints
1 ≤ numCourses ≤ 20000 ≤ prerequisites.length ≤ 5000- No duplicate edges.
Examples
Input: numCourses=2, prerequisites=[[1,0]] -> true
Input: numCourses=2, prerequisites=[[1,0],[0,1]] -> false (cycle)AD SLOT · 728×90