[LeetCode] 621. Task Scheduler
来源:互联网 发布:iis ip地址和域名限制 编辑:程序博客网 时间:2024/05/17 06:37
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 = 2Output: 8Explanation: 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> count(26, 0); for (auto tsk : tasks) count[tsk - 'A']++; int MaxSingleNTask = 0; for (auto cnt : count) MaxSingleNTask = max(MaxSingleNTask, cnt); int LeastCost = (MaxSingleNTask - 1) * (n + 1); for (auto cnt : count) LeastCost += (cnt == MaxSingleNTask); return max((int)tasks.size(), LeastCost); }};
阅读全文
0 0
- LeetCode 621. Task Scheduler
- 【LeetCode】621. Task Scheduler
- [LeetCode] 621. Task Scheduler
- Leetcode 621. Task Scheduler
- [leetcode]621. Task Scheduler
- leetcode 621. Task Scheduler
- Leetcode:621. Task Scheduler
- [LeetCode]621. Task Scheduler
- leetcode 621. Task Scheduler
- Leetcode 621. Task Scheduler
- leetcode 621. Task Scheduler
- leetcode 621. Task Scheduler (贪心)
- leetcode 621 Task Scheduler
- [Leetcode 621] Task Scheduler
- [leetcode] 621 Task Scheduler
- LeetCode Task Scheduler
- LeetCode-Task Scheduler
- LeetCode:Task Scheduler
- CSS3-2D转换
- Bson
- Bellman-Ford算法
- POJ 1004 Financial Management
- mongodb安装
- [LeetCode] 621. Task Scheduler
- Deep Learning 学习笔记整理系列之五
- jvm参数(全)
- base64字符串与图片之间的转换
- jvm垃圾回收——功效学
- Hive Analytics Functions row_number rank over partition by
- jvm垃圾回收——诊断垃圾收集问题
- android 反射 记录
- jvm垃圾回收——垃圾优先Garbage-First收集器