当前位置:网站首页>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;
}边栏推荐
- When the reference is assigned to auto
- 03 fastjason solves circular references
- 2020-08-23
- LeetCode - 460 LFU 缓存(设计 - 哈希表+双向链表 哈希表+平衡二叉树(TreeSet))*
- LeetCode - 706 设计哈希映射(设计) *
- STM32 general timer 1s delay to realize LED flashing
- Do you understand automatic packing and unpacking? What is the principle?
- LeetCode - 673. 最长递增子序列的个数
- Opencv notes 20 PCA
- Adaptiveavgpool1d internal implementation
猜你喜欢

Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction

Opencv note 21 frequency domain filtering

2021-10-27

2. Elment UI date selector formatting problem

Installation and removal of MySQL under Windows

LeetCode - 933 最近的请求次数

Leetcode - 933 number of recent requests
![[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)](/img/19/5dc152b3fadeb56de50768561ad659.jpg)
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)

Leetcode - 1670 conception de la file d'attente avant, moyenne et arrière (conception - deux files d'attente à double extrémité)

My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
随机推荐
Do you understand automatic packing and unpacking? What is the principle?
Leetcode - 1670 conception de la file d'attente avant, moyenne et arrière (conception - deux files d'attente à double extrémité)
4G module board level control interface designed by charging pile
CV learning notes - edge extraction
is_ power_ of_ 2 judge whether it is a multiple of 2
51 MCU tmod and timer configuration
LeetCode - 706 设计哈希映射(设计) *
CV learning notes ransca & image similarity comparison hash
Leetcode - 460 LFU cache (Design - hash table + bidirectional linked hash table + balanced binary tree (TreeSet))*
Liquid crystal display
2312、卖木头块 | 面试官与狂徒张三的那些事(leetcode,附思维导图 + 全部解法)
Sending and interrupt receiving of STM32 serial port
The data read by pandas is saved to the MySQL database
自動裝箱與拆箱了解嗎?原理是什麼?
Application of 51 single chip microcomputer timer
LeetCode - 900. RLE 迭代器
Yocto Technology Sharing Phase 4: Custom add package support
el-table X轴方向(横向)滚动条默认滑到右边
Pymssql controls SQL for Chinese queries
yocto 技术分享第四期:自定义增加软件包支持