630. Course Schedule III Hard
1/**
2 * [630] Course Schedule III
3 *
4 * There are n different online courses numbered from 1 to n. You are given an array courses where courses[i] = [durationi, lastDayi] indicate that the i^th course should be taken continuously for durationi days and must be finished before or on lastDayi.
5 * You will start on the 1^st day and you cannot take two or more courses simultaneously.
6 * Return the maximum number of courses that you can take.
7 *
8 * Example 1:
9 *
10 * Input: courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]
11 * Output: 3
12 * Explanation:
13 * There are totally 4 courses, but you can take 3 courses at most:
14 * First, take the 1^st course, it costs 100 days so you will finish it on the 100^th day, and ready to take the next course on the 101^st day.
15 * Second, take the 3^rd course, it costs 1000 days so you will finish it on the 1100^th day, and ready to take the next course on the 1101^st day.
16 * Third, take the 2^nd course, it costs 200 days so you will finish it on the 1300^th day.
17 * The 4^th course cannot be taken now, since you will finish it on the 3300^th day, which exceeds the closed date.
18 *
19 * Example 2:
20 *
21 * Input: courses = [[1,2]]
22 * Output: 1
23 *
24 * Example 3:
25 *
26 * Input: courses = [[3,2],[4,3]]
27 * Output: 0
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= courses.length <= 10^4
33 * 1 <= durationi, lastDayi <= 10^4
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/course-schedule-iii/
39// discuss: https://leetcode.com/problems/course-schedule-iii/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn schedule_course(courses: Vec<Vec<i32>>) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_630() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.