Queue-621. Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be done in one interval. For each interval, CPU could finish one task or just be idle.
However, there is a non-negative cooling interval n that means between two same tasks, there must be at least n intervals that CPU are doing different tasks or just be idle.
You need to return the least number of intervals the CPU will take to finish all the given tasks.
Example 1:
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8
Explanation: A -> B -> idle -> A -> B -> idle -> A -> B.
Note:
- The number of tasks is in the range [1, 10000].
- The integer n is in the range [0, 100].
class Solution {
public:
int leastInterval(vector<char>& tasks, int n) {
vector<int> cnt(, );
for (char task : tasks) {
++cnt[task - 'A'];
}
sort(cnt.begin(), cnt.end());
int i = , mx = cnt[], len = tasks.size();
while (i >= && cnt[i] == mx) --i;
return max(len, (mx - ) * (n + ) + - i);
}
};
Queue-621. Task Scheduler的更多相关文章
- 621. Task Scheduler
https://www.cnblogs.com/grandyang/p/7098764.html 将个数出现最多的那个字符作为分隔的标准,一定是最小的.所以这个时候只需要计算还需要添加多少个idel就 ...
- [leetcode]621. Task Scheduler任务调度
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where diffe ...
- 621. Task Scheduler CPU任务间隔分配器
[抄题]: Given a char array representing tasks CPU need to do. It contains capital letters A to Z where ...
- LeetCode 621. Task Scheduler
原题链接在这里:https://leetcode.com/problems/task-scheduler/description/ 题目: Given a char array representin ...
- [LeetCode] 621. Task Scheduler 任务调度
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where diffe ...
- 【LeetCode】621. Task Scheduler 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 公式法 日期 题目地址:https://leetco ...
- [LeetCode]621. Task Scheduler 任务安排 题解
题目描述 给定一个char数组,代表CPU需要做的任务,包含A-Z,不用考虑顺序,每个任务能在1个单位完成.但是有规定一个非负整数n代表两个相同任务之间需要至少n个时间单位.球最少数量的时间单位完成所 ...
- [leetcode] 621. Task Scheduler(medium)
原题 思路: 按频率最大的字母来分块,频率最大的字母个数-1为分成的块数,每一块个数为n+1 比如AAABBCE,n=2, 则分为A-A- +A AAABBBCCEE,n=2,则分为AB-AB- +A ...
- Windows Task Scheduler Fails With Error Code 2147943785
Problem: Windows Task Scheduler Fails With Error Code 2147943785 Solution: This is usually due to a ...
- 在Windows Server 2012的Task Scheduler里面配置自动发送邮件
最近在一台server上配置了每个周末备份数据库的定时任务,想顺手配置发送备份完成的邮件提醒我去Double Check一下备份结果. 悲剧地发现Send an email功能被新版的server给禁 ...
随机推荐
- Golang之Socket
go创建socket很简单 package main import ( "fmt" "net" ) func main() { //服务器监听地址 fmt.Pr ...
- x-www-form-urlencoded
就是application/x-www-from-urlencoded,会将表单内的数据转换为键值对,比如,name=java&age = 23 postman: 2.ajax传值
- tmux配置与用法整理
tmux常用命令与快捷键 http://www.111cn.net/sys/linux/59058.htm http://www.360doc.com/content/13/0709/13/13047 ...
- canvas标签的基本用法
1.canvas和其他标签一样使用,但是IE8以下是不支持的,可以在canvas里面加一个span用来提示,例如: <canvas> <span>IE8不支持canvas< ...
- struts2乱码问题
简介:做了个功能,用的struts2,表单提交到后台,接收后打印出来的数据乱码. 解决步骤: 1. struts.xml中配置<constant name="struts.i18n ...
- Tomcat连接池配置
今日做了个小网站,数据量不大,但当发布到虚拟主机上之后,接连不断的遇到各种问题. 被折磨了数日后,在网上查了大量的相关资料,现总结如下. 一.项目在上传到远程服务器的过程中,有可能丢失文件,或文件内容 ...
- 开始Java之旅
从今天起,cgg将给大家讲讲Java这种神奇的东西. 至于配置环境变量,大家可以看看我的博客:环境变量上面有详细解释. 下面先给大家一个公式: public class [文件名]{ ...
- 多网卡的7种bond模式原理 For Linux
多网卡的7种bond模式原理 Linux 多网卡绑定 网卡绑定mode共有七种(0~6) bond0.bond1.bond2.bond3.bond4.bond5.bond6 常用的有三种 mode=0 ...
- Devexpress VCL Build v2014 vol 14.2.4 发布
What's New in 14.2.4 (VCL Product Line) New Major Features in 14.2 What's New in VCL Products 14.2 ...
- window server2012服务器上如何安装nginx并启动
window环境下,Nginx安装启动的步骤如下: 把下载的window下的安装包,解压到一个不包含空格的路径下,比如:d:/Nginx 打开命令行窗口[win+R 输入cmd,然后确定]. 进入解压 ...