forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path80-1.py
More file actions
26 lines (19 loc) · 657 Bytes
/
80-1.py
File metadata and controls
26 lines (19 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import collections
from typing import List
class Solution:
def leastInterval(self, tasks: List[str], n: int) -> int:
counter = collections.Counter(tasks)
result = 0
while True:
sub_count = 0
# 개수 순 추출
for task, _ in counter.most_common(n + 1):
sub_count += 1
result += 1
counter.subtract(task)
# 0 이하인 아이템을 목록에서 완전히 제거
counter += collections.Counter()
if not counter:
break
result += n - sub_count + 1
return result