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的更多相关文章

  1. LeetCode 621. Task Scheduler

    原题链接在这里:https://leetcode.com/problems/task-scheduler/description/ 题目: Given a char array representin ...

  2. [LeetCode] 621. Task Scheduler 任务调度

    Given a char array representing tasks CPU need to do. It contains capital letters A to Z where diffe ...

  3. 【LeetCode】621. Task Scheduler 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 公式法 日期 题目地址:https://leetco ...

  4. [LeetCode]621. Task Scheduler 任务安排 题解

    题目描述 给定一个char数组,代表CPU需要做的任务,包含A-Z,不用考虑顺序,每个任务能在1个单位完成.但是有规定一个非负整数n代表两个相同任务之间需要至少n个时间单位.球最少数量的时间单位完成所 ...

  5. [leetcode]621. Task Scheduler任务调度

    Given a char array representing tasks CPU need to do. It contains capital letters A to Z where diffe ...

  6. [leetcode] 621. Task Scheduler(medium)

    原题 思路: 按频率最大的字母来分块,频率最大的字母个数-1为分成的块数,每一块个数为n+1 比如AAABBCE,n=2, 则分为A-A- +A AAABBBCCEE,n=2,则分为AB-AB- +A ...

  7. 621. Task Scheduler

    https://www.cnblogs.com/grandyang/p/7098764.html 将个数出现最多的那个字符作为分隔的标准,一定是最小的.所以这个时候只需要计算还需要添加多少个idel就 ...

  8. 621. Task Scheduler CPU任务间隔分配器

    [抄题]: Given a char array representing tasks CPU need to do. It contains capital letters A to Z where ...

  9. Windows Task Scheduler Fails With Error Code 2147943785

    Problem: Windows Task Scheduler Fails With Error Code 2147943785 Solution: This is usually due to a ...

  10. 在Windows Server 2012的Task Scheduler里面配置自动发送邮件

    最近在一台server上配置了每个周末备份数据库的定时任务,想顺手配置发送备份完成的邮件提醒我去Double Check一下备份结果. 悲剧地发现Send an email功能被新版的server给禁 ...

随机推荐

  1. form表单添加富文本编辑器

    <div class="control-group"> <label class="control-label">内容:</lab ...

  2. Asp.net Core中文转换成拼音

    一.概述 之前使用.net framework,可以使用Microsoft Visual Studio International Feature Pack 1.0 进行转换,现在使用asp.net ...

  3. numpy.random.uniform(记住文档网址)

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.uniform.html#numpy.random.uniform h ...

  4. 解决echarts内存泄露的问题

    clear方法和dispose方法 一种是调用clear方法,一种是dispose方法.第一种是清理echarts 但是不销毁实例.第二种是销毁实例,再次使用需要重新构建实例 1. var chart ...

  5. Ubuntu无法安装nginx

    1.问题Reading package lists... DoneBuilding dependency tree       Reading state information... DoneSom ...

  6. LaunchScreen 设置启动图片出现的问题

    更换启动图片的时候出现了一系列的小问题,让人头疼,怀疑人生. 1.更换了图片,显示还是老的图片!  -->重启手机,clean Xcode 2.设置布局的时候,请务必要这么布局,很完美! 如果你 ...

  7. ZROI 19.08.11模拟赛

    传送门 写在前面:为了保护正睿题目版权,这里不放题面,只写题解. dlstql,wsl A \(10pts:\) \(a=100,T=100\),对每个排列构造一个反的,一步到位即可. \(20pts ...

  8. Ubuntu中linux虚拟机全屏

    登录客户机操作系统.在虚拟机中装载CD驱动器启动终端,使用tar解压缩安装程序,然后执行vmware-insall.pl安装VMware Tools. 1.进入文件界面,找到左侧“设备”右击“安装VM ...

  9. java的一些总结

    抽象方法和普通方法的区别???? 1.抽象方法必须要通过继承才能被实现,然后才能被对象调用:普通方法在定义的同时就已经实现了. 2.抽象方法只需声明,而不需实现某些功能 3.抽象方法必须要被重写 20 ...

  10. 【NOIP2016提高A组五校联考1】道路规划

    题目 分析 我们考虑,当现在有一个合法的集合时,如何往里面增加一个点,使这个集合仍然合法. 假设现在有一个合法的集合, 那么当我们加入一个点,它的道路穿过来整个集合,那么 然后搞一遍最长下降子序列就可 ...