← 返回 doordash 的题目列表Course Schedule Problem
类型:online_judge
Given a number of courses and a list of prerequisite pairs, determine if you can finish all courses. Input: An integer n representing the total number of courses labeled from 0 to n-1, and a list prerequisites where each element prerequisites[i] is a pair [a, b] indicating that to take course a you must first take course b. Output: Return true if you can finish all courses, otherwise return false.
Example:
Input: n = 2, prerequisites = [[1,0]] Output: true
Input: n = 2, prerequisites = [[1,0],[0,1]] Output: false
Constraints:
1 <= n <= 10^5
0 <= prerequisites.length <= 5 * 10^4
Example
Input
2
[[1,0]]