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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 206. Reverse Linked List (0) | 2024.03.21 |
---|---|
[Leetcode] 1669. Merge In Between Linked Lists (0) | 2024.03.20 |
[Leetcode] 452. Minimum Number of Arrows to Burst Balloons (0) | 2024.03.19 |
[Leetcode] 57. Insert Interval (0) | 2024.03.17 |
[Leetcode] 3083. Existence of a Substring in a String and Its Reverse (0) | 2024.03.17 |