当前位置:网站首页>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;
}
边栏推荐
- Opencv notes 17 template matching
- Liquid crystal display
- Opencv image rotation
- The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving
- Leetcode bit operation
- CV learning notes ransca & image similarity comparison hash
- I think all friends should know that the basic law of learning is: from easy to difficult
- Opencv feature extraction - hog
- Drive and control program of Dianchuan charging board for charging pile design
- SCM is now overwhelming, a wide variety, so that developers are overwhelmed
猜你喜欢
Installation and removal of MySQL under Windows
Leetcode interview question 17.20 Continuous median (large top pile + small top pile)
ADS simulation design of class AB RF power amplifier
Assignment to '*' form incompatible pointer type 'linkstack' {aka '*'} problem solving
The underlying principle of vector
MySQL root user needs sudo login
Opencv feature extraction - hog
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
LeetCode - 933 最近的请求次数
Connect Alibaba cloud servers in the form of key pairs
随机推荐
Yocto Technology Sharing Phase 4: Custom add package support
Dictionary tree prefix tree trie
Leetcode - 1670 design front, middle and rear queues (Design - two double ended queues)
On the problem of reference assignment to reference
Opencv feature extraction - hog
CV learning notes - edge extraction
[combinatorics] combinatorial existence theorem (three combinatorial existence theorems | finite poset decomposition theorem | Ramsey theorem | existence theorem of different representative systems |
STM32 general timer 1s delay to realize LED flashing
QT setting suspension button
Serial communication based on 51 single chip microcomputer
YOLO_ V1 summary
LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
el-table X轴方向(横向)滚动条默认滑到右边
Google browser plug-in recommendation
Opencv histogram equalization
Opencv note 21 frequency domain filtering
JS foundation - prototype prototype chain and macro task / micro task / event mechanism
Positive and negative sample division and architecture understanding in image classification and target detection
openEuler kernel 技術分享 - 第1期 - kdump 基本原理、使用及案例介紹
Screen display of charging pile design -- led driver ta6932