LeetCode每日一题(2589. Minimum Time to Complete All Tasks)

给定一个二维数组tasks,表示计算机需要在指定时间范围内运行的任务及其持续时间。计算机可以同时运行无限数量的任务。返回完成所有任务所需的计算机开机的最短时间。例如,对于[[2,3,1],[4,5,1],[1,5,2]],计算机只需开机2秒即可完成所有任务。" 81155375,4895219,理解DES加密算法:安全基石与流程解析,"['对称加密', '数据加密', 'DES算法', '密码学']
摘要由CSDN通过智能技术生成

There is a computer that can run an unlimited number of tasks at the same time. You are given a 2D integer array tasks where tasks[i] = [starti, endi, durationi] indicates that the ith task should run for a total of durationi seconds (not necessarily continuous) within the inclusive time range [starti, endi].

You may turn on the computer only when it needs to run a task. You can also turn it off if it is idle.

Return the minimum time during which the computer should be turned on to complete all tasks.

Example 1:

Input: tasks = [[2,3,1],[4,5,1],[1,5,2]]
Output: 2

Explanation:

  • The first task can be run in the inclusive time range [2, 2].
  • The second task can be run in the inclusive time range [5, 5].
  • The third task can be run in the two inclusive time ranges [2, 2] and [5, 5].
    The computer will be on for a total of 2 seconds.

Example 2:

Input: tasks = [[1,3,2],[2,5,3],[5,6,2]]
Output: 4

Explanation:

  • The first task can be run in the inclusive time range [2, 3].
  • The second task can be run in the inclusive time ranges [2, 3] and [5, 5].
  • The third task can be run in the two inclusive time range [5, 6].
    The computer will be on for a total of 4 seconds.

Constraints:

  • 1 <= tasks.length <= 2000
  • tasks[i].length == 3
  • 1 <= starti, endi <= 2000
  • 1 <= durationi <= endi - starti + 1

高端的问题往往只需要最朴素的解法

  1. 按 end 升序排
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值