leetcode-mid-others-621. Task Scheduler
mycode 53.01%
这个题在纸上画一画就知道啦,只要出现次数最多的字母能够满足要求,其他更少的字母穿插在其中,间隔就更满足<n啦,当然,最后不要忘记加上尾巴哦,尾巴和出现次数最多的字母的种类有关哦!
class Solution(object):
def leastInterval(self, tasks, n):
"""
:type tasks: List[str]
:type n: int
:rtype: int
"""
from collections import Counter
count = Counter(tasks)
total = 1
maxcount = count.most_common()[0][1]
print(maxcount)
for num,c in count.most_common()[1:]:
if c == maxcount:
total += 1
return max(len(tasks),(maxcount-1)*(n+1)+total)
参考:
class Solution(object):
def leastInterval(self, tasks, n):
"""
:type tasks: List[str]
:type n: int
:rtype: int
"""
lenT = len(tasks)
res = rem = max_cnt = 0
dic = collections.defaultdict(int) for ch in tasks:
dic[ch]+=1
for val in dic.values():
if val>max_cnt:
max_cnt = val
rem = 0
elif val==max_cnt:
rem+=1 #与max_cnt出现频率相同的其他元素个数
tmp = (max_cnt-1)*(n+1)+1 + rem # n很长的情况
res = max(lenT, tmp)
return res
leetcode-mid-others-621. Task Scheduler的更多相关文章
- 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任务调度
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where diffe ...
- [leetcode] 621. Task Scheduler(medium)
原题 思路: 按频率最大的字母来分块,频率最大的字母个数-1为分成的块数,每一块个数为n+1 比如AAABBCE,n=2, 则分为A-A- +A AAABBBCCEE,n=2,则分为AB-AB- +A ...
- 621. Task Scheduler
https://www.cnblogs.com/grandyang/p/7098764.html 将个数出现最多的那个字符作为分隔的标准,一定是最小的.所以这个时候只需要计算还需要添加多少个idel就 ...
- 621. Task Scheduler CPU任务间隔分配器
[抄题]: Given a char array representing tasks CPU need to do. It contains capital letters A to Z where ...
- 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给禁 ...
随机推荐
- AQS之Condition
一.引言 一般我们在使用锁的Condition时,我们一般都是这么使用,以ReentrantLock为例, ReentrantLock lock = new ReentrantLock(); Cond ...
- 092、部署Graylog日志系统(2019-05-16 周四)
参考https://www.cnblogs.com/CloudMan6/p/7808708.html Graylog 是与 ELK 可以相提并论的一款几种式日志管理方案,支持数据收集.检索.可视化 ...
- 多层 iframe 嵌套 js 方法调用
一下午一个这破问题,浪费了不少时间,怎么也实现不了我的上上级iframe 刷新.NND. 实现了,记录一下下吧: window.parent.parent.document.getElementByI ...
- 初探CSS -3 语法
CSS 语法 实例 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- PC端QQ协议说明,完美搞定QQ智能助手
一. 实验目的: 在虚拟机下NAT模式下通过Wireshark抓包,分析QQ的传输模式.了解QQ在传输信息过程中用到的协议.分析在Nat模式下,信息传输的穿透性. 二. 实验环境: Win7 专业版3 ...
- tp5 apache 转 nginx 需要配置的伪静态
location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$ last; break; } }
- 001-cut 的用法
[root@zabbix ~]# , /etc/passwd root: bin: daemon: adm: shutdown: halt: mail: operator: games: nobody ...
- Charles在windows上抓取本地python的 request请求
首先打开charles,在Proxy中打开Windows Proxy,这样才能抓取本地请求 python代码中报错Caused by SSLError(SSLError(1, '[SSL: CERTI ...
- JAVA笔记18-容器之二增强的for循环(不重要)
JDK1.5增强的for循环(foreach??)
- 【leetcode】Network Delay Time
题目: There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edge ...