python代码如下
class Solution(object):
def leastInterval(self, tasks, n):
"""
:type tasks: List[str]
:type n: int
:rtype: int
"""
if n == 0:
return len(tasks)
from collections import Counter
dic = Counter(tasks)
max_cnt = max(dic.values())
last_row = sum([1 for i in dic if dic[i] == max_cnt])
return max((max_cnt-1)*(n+1)+last_row, len(tasks))
利用 【桶思想】 ,思路还是比较简单的,很妙,参考链接如下,图文并茂
参考链接: https://leetcode-cn.com/problems/task-scheduler/solution/621-ren-wu-diao-du-qi-dui-you-xian-dui-l-e5h8/