leetcode face面试题 Minimal run time scheduler
来源:互联网 发布:360全景源码 编辑:程序博客网 时间:2024/06/05 01:05
题意:
Given a task sequence tasks
such as ABBABBC
, and an integer k
, which is the cool down time between two same tasks. Assume the execution for each individual task is 1 unit.
For example, if k = 3
, then tasks BB
takes a total of 5 unit time to finish, because B
takes 1 unit of time to execute, then wait for 3 unit, and execute the second B
again for another unit of time. So 1 + 3 + 1 = 5.
Given a task sequence and the cool down time, return the total execution time.
Follow up: Given a task sequence and the cool down time, rearrange the task sequence such that the execution time is minimal.
思路: 关注出现次数最多的那个字符串即可
代码:
unsigned min_runtime(vector<string>& vec, const int K) {if (vec.empty()) return 0; unordered_map<string, int> hashtable;for (auto str : vec)hashtable[str]++;vector<int> cnt;for (auto elem : hashtable)cnt.push_back(elem.second);sort(cnt.rbegin(), cnt.rend());int frequency = 1;for (int i = 1; i < cnt.size(); ++i) {if (cnt[0] == cnt[i])frequency++;elsebreak;}unsigned ret = cnt[0] + (cnt[0] - 1) * K + frequency - 1;return max(ret, (unsigned)vec.size()); }
0 0
- leetcode face面试题 Minimal run time scheduler
- Linux Scheduler – CFS and Virtual Run Time (vruntime)
- run time
- run Time
- Two Sum --- LeetCode 面试题
- LRU Cache --- LeetCode 面试题
- LeetCode中的DataBase面试题
- real-time scheduler man page
- Robust Real-time Face Detection
- 面剔除 Face Culling
- 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
- Matlab 二值图像label regions
- 从list集合里随机获取数据
- STL-vector
- 虚函数
- angularjs学习笔记-封装公共模块
- leetcode face面试题 Minimal run time scheduler
- Reservoir Sampling 蓄水池抽样算法,经典抽样
- 定期发项目报告好处
- 电力猫工作原理及使用
- python初见
- windows下,Qt连接Mysql
- Mysql中的数据类型
- HDU1226 超级密码
- javascript 文本框