博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 621: Task Scheduler
阅读量:6920 次
发布时间:2019-06-27

本文共 1328 字,大约阅读时间需要 4 分钟。

class Solution {    class Task {        public char task;        public int numTasks;    }    public int leastInterval(char[] tasks, int n) {        if (tasks.length == 0) {            return 0;        }        Map
map = new HashMap<>(); for (char c : tasks) { if (!map.containsKey(c)) { Task t = new Task(); t.task = c; t.numTasks = 0; map.put(c, t); } map.get(c).numTasks++; } Queue
queue = new PriorityQueue<>((t1, t2) -> t2.numTasks - t1.numTasks); queue.addAll(map.values()); int result = 0; while (!queue.isEmpty()) { int k = n + 1; List
taskList = new ArrayList<>(); while (k > 0 && !queue.isEmpty()) { Task current = queue.poll(); current.numTasks--; taskList.add(current); result++; k--; } for (Task task : taskList) { if (task.numTasks > 0) { queue.offer(task); } } if (queue.isEmpty()) break; result += k; } return result; }}

 

转载于:https://www.cnblogs.com/shuashuashua/p/7542505.html

你可能感兴趣的文章
Lync 2010与2013共存无法共享PPT白板功能
查看>>
程序员十大撩妹技能
查看>>
keepalived体系结构及相关配置
查看>>
Linux小技巧一:通过文件内的关键字来查找文件
查看>>
win7旗舰版开机蓝屏
查看>>
Linux平台下如何看OS历史的性能数据
查看>>
HTML5 之路的绊脚石
查看>>
HTML5理想与现实的博弈
查看>>
Office 365管理员指引 1 ——Office 365 Admin Center
查看>>
Apache CAS 单点登录下载(1)
查看>>
fflush函数
查看>>
基于函数的索引
查看>>
CentOS7更改默认网卡
查看>>
C盘太满清理技巧
查看>>
纽曼纽扣偷袭奇酷青春,YunOS与360OS会不会发生点什么
查看>>
C#学习常用方法(4000)---Activator.CreateInstance方法
查看>>
Unity5.0 EventSystem事件系统的详细说明
查看>>
运维采集技术分享: 通过WMI监控NAT后的Windows系统
查看>>
MFC_定时器
查看>>
Android-避免出现bitmap内存限制OUT OF MEMORY的一种方法
查看>>