Coding Round 2
Mid-Level
programming
LeetCode #207 - Course Schedule
There are a total of
Input:
Output:
Explanation: There are a total of 2 courses to take. To take course 1 you should have taken course 0 beforehand. Thus it is possible.Example 2:
Input:
Output:
Explanation: A cycle exists.Constraints:
numCourses courses you have to take, labeled from 0 to numCourses-1. Some courses may have prerequisites, represented as a list of pairs [a, b] meaning you must take course b before course a. Find out if you can finish all courses. Return true if you can finish all courses, otherwise return false.Example 1:Input:
numCourses = 2, prerequisites = [[1, 0]]Output:
trueExplanation: There are a total of 2 courses to take. To take course 1 you should have taken course 0 beforehand. Thus it is possible.Example 2:
Input:
numCourses = 2, prerequisites = [[1, 0], [0, 1]]Output:
falseExplanation: A cycle exists.Constraints:
- 0 <= numCourses <= 2000
- 0 <= prerequisites.length <= 5000
Suggested Answer