Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- class Solution:
- def leastInterval(self, tasks: List[str], n: int) -> int:
- if not tasks:
- return 0
- task_dict = defaultdict(int)
- for task in tasks:
- task_dict[task] += 1
- task_list = [val for val in task_dict.values()]
- task_list.sort(reverse=True)
- print(task_list)
- total = 0
- count = -1
- reset = True
- del_list = []
- while task_list:
- task_list.sort(reverse=True)
- # for i in range(0,len(task_list)-1):
- # if task_list[i]<task_list[i+1]:
- # task_list[i], task_list[i+1] = task_list[i+1], task_list[i]
- # else:
- # break
- if not reset:
- total += (n-count)
- count = -1
- reset = False
- for i in range(0,len(task_list)):
- task_list[i] -= 1
- if task_list[i] == 0:
- del_list.append(i)
- count += 1
- total += 1
- if count == n:
- count = -1
- reset = True
- break
- while del_list:
- task_list.pop(del_list.pop())
- return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement