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给禁 ...
随机推荐
- sql认识
DDL – Data Definition Language数据定义语言DML – Data Manipulation Language数据操作语言DCL – Data Control Languag ...
- type=file 上传图片限制 类型和尺寸 方法
<form> <input type="file" name="pic" id="pic" accept="im ...
- HTTP常用状态码详解
HTTP状态码: HTTP定义遵循一条规则:所有状态码的第一个数字代表了响应的状态.1表示消息:2表示成功:3表示重定向:4表示请求错误:5.6表示服务器错误.如下图: 1xx: 这一类型的状态码,代 ...
- PHP的htmlspecialchars、strip_tags、addslashes
PHP的htmlspecialchars.strip_tags.addslashes是网页程序开发中常见的函数,今天就来详细讲述这些函数的用法: 1.函数strip_tags:去掉 HTML 及 PH ...
- postman 请求
1.设置File ->setting -> General 2.设置header 3.填写参数body
- Nginx Windows下安装使用及权重分配
内容目录 Nginx 下载启动Nginx关闭NginxNginx使用注意事项使用Nginx代理服务器做负载均衡Nginx配置静态资源Nginx权重分配方式Nginx负载均衡参数描述写在最后 Nginx ...
- 在centOS7.2上编译gcc4.1.2
1.下载安装gcc4.1.2安装包 wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.1.2/gcc-4.1.2.tar.bz2 注:其他版本的安装包可以在上级目录寻找到. ...
- Java基本的程序结构设计 基本类型的输入输出
读取输入: java.util.Scanner 一个可以使用正则表达式来分析基本类型和字符串的简单文本扫描器. 了解: Scanner 使用分隔符模式将其输入分解为标记,默认情况下该分隔符模式与空白匹 ...
- 使用RegisterPointerInputTarget时的一些注意事项
RegisterPointerInputTarget :允许调用者注册一个目标窗口,指定类型的所有指针输入都重定向到该窗口. 要使用它必须使 UIAccess = true,见下图 在设置完之后,需要 ...
- 推荐几个天气Api接口 (可在小程序中使用)
国内的地图软件基本是支持查询天气的唯独腾讯地图不支持天气查询,当然其他天气平台提供的接口也是够个人使用的 1.高德地图(高德地图开发者平台)支持获取实时天气数据 2.百度地图(百度地图开放平台)支持获 ...