亚马逊笔试 2019 年 5 月软件开发工程师 I
您总共需要学习 n 门课程,标记为从 0 到 n-1。
有些课程可能有先决条件,例如,要参加课程 0,您必须先参加课程 1,这表示为一对:[0, 1]
鉴于课程总数和先决条件对列表,您是否有可能完成所有课程?
Examples:
Input: 2,
[1, 0]
Output: true
Explanation: There are a total of 2 courses to take.
To take course 1 you should have finished course 0. So it is possible.
Input: 2, [[1, 0], [0, 1]]
Output: false
Explanation: There are a total of 2 courses to take.
To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.