207. Course Schedule Medium

@problem@discussion
#Depth-First Search#Breadth-First Search#Graph#Topological Sort



1/**
2 * [207] Course Schedule
3 *
4 * There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.
5 * 
6 * 	For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1.
7 * 
8 * Return true if you can finish all courses. Otherwise, return false.
9 *  
10 * Example 1:
11 * 
12 * Input: numCourses = 2, prerequisites = [[1,0]]
13 * Output: true
14 * Explanation: There are a total of 2 courses to take. 
15 * To take course 1 you should have finished course 0. So it is possible.
16 * 
17 * Example 2:
18 * 
19 * Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
20 * Output: false
21 * Explanation: There are a total of 2 courses to take. 
22 * 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.
23 * 
24 *  
25 * Constraints:
26 * 
27 * 	1 <= numCourses <= 2000
28 * 	0 <= prerequisites.length <= 5000
29 * 	prerequisites[i].length == 2
30 * 	0 <= ai, bi < numCourses
31 * 	All the pairs prerequisites[i] are unique.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/course-schedule/
37// discuss: https://leetcode.com/problems/course-schedule/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn can_finish(num_courses: i32, prerequisites: Vec<Vec<i32>>) -> bool {
43        false
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_207() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.