File tree 1 file changed +5
-12
lines changed
1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ from collections import Counter
35
35
36
36
class Solution:
37
37
def leastInterval(self, tasks: List[str], n: int) -> int:
38
- n_intervals = n_idles = 0
38
+ n_intervals = 0
39
39
ch_to_count = Counter(tasks)
40
40
max_heap = [-count for count in ch_to_count.values()]
41
41
heapq.heapify(max_heap)
@@ -46,18 +46,11 @@ class Solution:
46
46
popped_items.append(heapq.heappop(max_heap))
47
47
else:
48
48
break
49
-
50
- n_intervals += len(popped_items) + n_idles
51
- if len(popped_items) < n:
52
- n_idles = n - len(popped_items) + 1
53
- elif len(popped_items) > n:
54
- n_idles = 0
55
- else: # len(popped_items) == n
56
- n_idles = 1
57
49
58
- popped_items = [count+1 for count in popped_items if count+1 != 0]
59
- max_heap += popped_items
50
+ max_heap += [count+1 for count in popped_items if count+1 != 0]
60
51
heapq.heapify(max_heap)
61
52
62
- return n_intervals
53
+ n_intervals += len(popped_items) if len(max_heap) == 0 else n+1
54
+
55
+ return n_intervals
63
56
```
You can’t perform that action at this time.
0 commit comments