当前位置:网站首页>20220610 other: Task Scheduler
20220610 other: Task Scheduler
2022-07-03 10:12:00 【Seeyouagain】
Title Description : Here's an array of characters for you tasks It means CPU List of tasks to be performed . Each letter represents a different kind of task . Tasks can be performed in any order , And every task can be in 1 In unit time . At any unit time ,CPU Can complete a task , Or on standby .
However , Two Same kind There must be integer length between tasks of n The cooling time of , So at least there's continuity n In units of time CPU On different missions , Or on standby .
You need to calculate what it takes to complete all the tasks The shortest time .
coded :
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;
}
边栏推荐
- Tensorflow2.0 save model
- 2.1 Dynamic programming and case study: Jack‘s car rental
- Leetcode - 933 number of recent requests
- LeetCode - 1172 餐盘栈 (设计 - List + 小顶堆 + 栈))
- Dictionary tree prefix tree trie
- Design of charging pile mqtt transplantation based on 4G EC20 module
- Flutter 退出当前操作二次确认怎么做才更优雅?
- getopt_ Typical use of long function
- Opencv interview guide
- MySQL root user needs sudo login
猜你喜欢
LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
Adaptiveavgpool1d internal implementation
Leetcode 300 最长上升子序列
2. Elment UI date selector formatting problem
2312. Selling wood blocks | things about the interviewer and crazy Zhang San (leetcode, with mind map + all solutions)
LeetCode - 933 最近的请求次数
Pymssql controls SQL for Chinese queries
Connect Alibaba cloud servers in the form of key pairs
Leetcode-513:找树的左下角值
Opencv histogram equalization
随机推荐
Opencv gray histogram, histogram specification
CV learning notes alexnet
2312. Selling wood blocks | things about the interviewer and crazy Zhang San (leetcode, with mind map + all solutions)
20220605数学:两数相除
LeetCode - 706 设计哈希映射(设计) *
Leetcode-100:相同的树
openCV+dlib实现给蒙娜丽莎换脸
20220610其他:任务调度器
Discrete-event system
2021-11-11 standard thread library
Cases of OpenCV image enhancement
2.2 DP: Value Iteration & Gambler‘s Problem
yocto 技术分享第四期:自定义增加软件包支持
CV learning notes - Stereo Vision (point cloud model, spin image, 3D reconstruction)
CV learning notes - deep learning
Implementation of "quick start electronic" window dragging
Matplotlib drawing
My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
openCV+dlib實現給蒙娜麗莎換臉
4G module board level control interface designed by charging pile