Участник:Lenaermakova/Task Scheduler

Материал из DISCOPAL
Перейти к: навигация, поиск

https://leetcode.com/problems/task-scheduler/

class Solution(object):
    def leastInterval(self, tasks, n):
        task_count = {}
        for t in tasks:
            if t in task_count.keys():
                task_count[t] += 1
            else:
                task_count[t] = 1
        max_count = max(list(task_count.values()))
        t = 0
        for task in task_count.values():
            if task == max_count:
                t+=1
        return max(len(tasks), (max_count-1)*(n+1)+t)