当前位置:网站首页>20220610其他:任务调度器
20220610其他:任务调度器
2022-07-03 09:20:00 【丿SeeYouAgain】
题目描述:给你一个用字符数组 tasks 表示的 CPU 需要执行的任务列表。其中每个字母表示一种不同种类的任务。任务可以以任意顺序执行,并且每个任务都可以在 1 个单位时间内执行完。在任何一个单位时间,CPU 可以完成一个任务,或者处于待命状态。
然而,两个 相同种类 的任务之间必须有长度为整数 n 的冷却时间,因此至少有连续 n 个单位时间内 CPU 在执行不同的任务,或者在待命状态。
你需要计算完成所有任务所需要的 最短时间 。
编码实现:
public static int leastInterval(char[] tasks, int n) {
int maxSize = 0, maxCount = 0;
int hash[] = new int[26];
int length = tasks.length;
for (int i=0; i< length; i++) {
hash[tasks[i] - 'A']++;
if (hash[tasks[i] - 'A'] > maxSize) {
maxSize = hash[tasks[i] - 'A'];
}
}
for (int i=0; i<26; i++) {
if (hash[i] == maxSize) maxCount++;
}
return length > (maxSize-1)*(n+1)+maxCount ? length : (maxSize-1)*(n+1)+maxCount;
}
边栏推荐
- Modelcheckpoint auto save model
- My openwrt learning notes (V): choice of openwrt development hardware platform - mt7688
- Leetcode 300 最长上升子序列
- yocto 技术分享第四期:自定义增加软件包支持
- Design of charging pile mqtt transplantation based on 4G EC20 module
- Opencv interview guide
- 2021-01-03
- On the problem of reference assignment to reference
- Markdown latex full quantifier and existential quantifier (for all, existential)
- (2)接口中新增的方法
猜你喜欢
LeetCode - 508. Sum of subtree elements with the most occurrences (traversal of binary tree)
使用密钥对的形式连接阿里云服务器
CV learning notes - image filter
Leetcode 300 longest ascending subsequence
It is difficult to quantify the extent to which a single-chip computer can find a job
Stm32f407 key interrupt
ADS simulation design of class AB RF power amplifier
Timer and counter of 51 single chip microcomputer
El table X-axis direction (horizontal) scroll bar slides to the right by default
Development of intelligent charging pile (I): overview of the overall design of the system
随机推荐
LeetCode - 900. RLE 迭代器
LeetCode - 895 最大频率栈(设计- 哈希表+优先队列 哈希表 + 栈) *
CV learning notes ransca & image similarity comparison hash
LeetCode 面试题 17.20. 连续中值(大顶堆+小顶堆)
Application of 51 single chip microcomputer timer
Installation and removal of MySQL under Windows
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
YOLO_ V1 summary
03 FastJson 解决循环引用
Leetcode bit operation
Not many people can finally bring their interests to college graduation
01仿B站项目业务架构
2. Elment UI date selector formatting problem
Swing transformer details-2
Serial communication based on 51 single chip microcomputer
03 fastjason solves circular references
Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
Yocto technology sharing phase IV: customize and add software package support
openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍
LeetCode - 673. 最长递增子序列的个数