|
| 1 | +<h2><a href="https://leetcode.com/problems/course-schedule">207. Course Schedule</a></h2><h3>Medium</h3><hr><p>There are a total of <code>numCourses</code> courses you have to take, labeled from <code>0</code> to <code>numCourses - 1</code>. You are given an array <code>prerequisites</code> where <code>prerequisites[i] = [a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you <strong>must</strong> take course <code>b<sub>i</sub></code> first if you want to take course <code>a<sub>i</sub></code>.</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>For example, the pair <code>[0, 1]</code>, indicates that to take course <code>0</code> you have to first take course <code>1</code>.</li> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p>Return <code>true</code> if you can finish all courses. Otherwise, return <code>false</code>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> numCourses = 2, prerequisites = [[1,0]] |
| 14 | +<strong>Output:</strong> true |
| 15 | +<strong>Explanation:</strong> There are a total of 2 courses to take. |
| 16 | +To take course 1 you should have finished course 0. So it is possible. |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p><strong class="example">Example 2:</strong></p> |
| 20 | + |
| 21 | +<pre> |
| 22 | +<strong>Input:</strong> numCourses = 2, prerequisites = [[1,0],[0,1]] |
| 23 | +<strong>Output:</strong> false |
| 24 | +<strong>Explanation:</strong> There are a total of 2 courses to take. |
| 25 | +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. |
| 26 | +</pre> |
| 27 | + |
| 28 | +<p> </p> |
| 29 | +<p><strong>Constraints:</strong></p> |
| 30 | + |
| 31 | +<ul> |
| 32 | + <li><code>1 <= numCourses <= 2000</code></li> |
| 33 | + <li><code>0 <= prerequisites.length <= 5000</code></li> |
| 34 | + <li><code>prerequisites[i].length == 2</code></li> |
| 35 | + <li><code>0 <= a<sub>i</sub>, b<sub>i</sub> < numCourses</code></li> |
| 36 | + <li>All the pairs prerequisites[i] are <strong>unique</strong>.</li> |
| 37 | +</ul> |
0 commit comments