课程调度问题:LeetCode 630. Course Schedule III

题目描述:
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


解题思路:

  1. 将课程按due time排序,due time排序在前的表示优先级较高,需要先完成;
  2. 遍历排序后的课程,若某个课程可在due time前结束,则将该课程的耗费时间加入调度list中,并更新已花费的时间consumingTIme的值;
  3. 若某个课程不可在due time前结束,则首先判断该课程耗费时间是否比list中最长的耗费时间还要长,若是,则不添加该课程;若不是,则删除list中最长的耗费时间并将该时间加入list中。

原理:

  • 按due time排序可保证所有课程较好的时间顺序加入li
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值