Skip to content

Commit 2ae20b0

Browse files
Merge pull request #2994 from coopers/0621
Update 0621-task-scheduler.py
2 parents c6f7c66 + dbdc945 commit 2ae20b0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

python/0621-task-scheduler.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ def leastInterval(self, tasks: List[str], n: int) -> int:
1818
if q and q[0][1] == time:
1919
heapq.heappush(maxHeap, q.popleft()[0])
2020
return time
21+
22+
23+
# Greedy algorithm
24+
class Solution(object):
25+
def leastInterval(self, tasks: List[str], n: int) -> int:
26+
counter = collections.Counter(tasks)
27+
max_count = max(counter.values())
28+
min_time = (max_count - 1) * (n + 1) + \
29+
sum(map(lambda count: count == max_count, counter.values()))
30+
31+
return max(min_time, len(tasks))

0 commit comments

Comments
 (0)