There are numCourses courses labeled 0 to numCourses - 1. You're given an array prerequisites where prerequisites[i] = [a, b] means course b must be taken before course a.
Return true if it's possible to finish every course, and false otherwise.
Examples
Example 1
- Input
- numCourses = 2, prerequisites = [[1, 0]]
- Output
- true
- Why
- Take course 0, then course 1.
Example 2
- Input
- numCourses = 2, prerequisites = [[1, 0], [0, 1]]
- Output
- false
- Why
- Each course needs the other one first, so neither can start.
Constraints
1 <= numCourses <= 20000 <= prerequisites.length <= 5000- All pairs
[a, b]are distinct.