본문 바로가기

IT/코딩테스트

[Leetcode] 621. Task Scheduler

728x90

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

class Solution:
    def leastInterval(self, tasks: List[str], n: int) -> int:
        frequency = [0] * 26

        for t in tasks:
            frequency[ord(t) - ord('A')] += 1
        
        max_frequency_count = frequency.count(max(frequency))

        shortest = len(tasks)
        longest = (max(frequency) - 1) * (n + 1) + max_frequency_count
                
        return max(shortest, longest)
728x90