← 返回 amazon 的题目列表Course Schedule Challenges
类型:online_judge
You need to complete two tasks related to course planning.
Task 1: Course Schedule
Given the number of courses n and a list of prerequisites prerequisites, where each prerequisite is a pair [a, b] that denotes course a must be taken after course b. Determine if it's possible to finish all courses.
Example Input:
2
[[1, 0]]
Example Output:
true
Task 2: Course Schedule II
Given the total number of courses and their prerequisites, return an order in which you can take all the courses. If such an order exists, return the ordering, otherwise return an empty array.
Example Input:
4
[[1, 0], [2, 0], [3, 1], [3, 2]]
Example Output:
[0, 1, 2, 3]
Example
Input
2
[[1, 0]]