题目描述:
There are n different online courses numbered from 1 to n. Each course has some duration(course length) t and closed on dth day. A course should be taken continuously for t days and must be finished before or on the dth day. You will start at the 1st day.
Given n online courses represented by pairs (t,d), your task is to find the maximal number of courses that can be taken.
示例:
Input: [[100, 200], [200, 1300], [1000, 1250], [2000, 3200]]
Output: 3
解题思路:
- 将课程按due time排序,due time排序在前的表示优先级较高,需要先完成;
- 遍历排序后的课程,若某个课程可在due time前结束,则将该课程的耗费时间加入调度list中,并更新已花费的时间consumingTIme的值;
- 若某个课程不可在due time前结束,则首先判断该课程耗费时间是否比list中最长的耗费时间还要长,若是,则不添加该课程;若不是,则删除list中最长的耗费时间并将该时间加入list中。
原理:
- 按due time排序可保证所有课程较好的时间顺序加入li