Leetcode 2895. Minimum Processing Time

  • [Leetcode 2895. Minimum Processing Time](#Leetcode 2895. Minimum Processing Time)
    • [1. 解题思路](#1. 解题思路)
    • [2. 代码实现](#2. 代码实现)

1. 解题思路

这一题整体上来说其实没啥难度,就是一个greedy算法,只需要想明白耗时长的任务一定要优先执行,不存在某个耗时长的任务后执行可以更快的完成的情况。

因此,我们只需要将耗时倒序排列之后顺序分配给各个闲置的CPU即可。

2. 代码实现

给出python代码实现如下:

python 复制代码
class Solution:
    def minProcessingTime(self, processorTime: List[int], tasks: List[int]) -> int:
        processorTime = sorted(processorTime)
        tasks = sorted(tasks, reverse=True)
        n = len(processorTime)
        ans = max(processorTime[i] + tasks[4*i] for i in range(n))
        return ans

提交代码评测得到:耗时591ms,占用内存32.8MB。

相关推荐
午彦琳8 小时前
2026.9.17
数据结构·算法·leetcode
木井巳9 小时前
【记忆化搜索】不同路径
java·算法·leetcode·深度优先·剪枝·推荐算法
All for pursuit.12 小时前
【链表-9】146.LRU缓存
数据结构·c++·算法·leetcode
圣保罗的大教堂12 小时前
leetcode 1477. 找两个和为目标值且不重叠的子数组 中等
leetcode
hanlin0313 小时前
刷题笔记:力扣第144题-二叉树的前序遍历
笔记·算法·leetcode
圣保罗的大教堂15 小时前
leetcode 3629. 通过质数传送到达终点的最少跳跃次数 中等
leetcode
圣保罗的大教堂15 小时前
leetcode 1914. 循环轮转矩阵 中等
leetcode
wabs66616 小时前
关于二叉树【力扣100.相同的树的思考】
数据结构·c++·算法·leetcode·二叉树·递归法
alphaTao17 小时前
LeetCode 每日一题 2026/9/14-2026/9/20
算法·leetcode
hanlin0317 小时前
刷题笔记:力扣第560题-和为k的子数组
笔记·算法·leetcode