Skip to content

Commit 9d97e13

Browse files
author
Chris Cooper
committed
Refactor
I hope this is easier to read.
1 parent c80ba45 commit 9d97e13

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

python/0621-task-scheduler.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ def leastInterval(self, tasks: List[str], n: int) -> int:
2323
# Greedy algorithm
2424
class Solution(object):
2525
def leastInterval(self, tasks: List[str], n: int) -> int:
26-
counts = collections.Counter(tasks)
27-
max_count = max(counts.values())
28-
min_time = (max_count - 1) * (n + 1)
29-
30-
for count in counts.values():
31-
if count == max_count:
32-
min_time += 1
26+
counter = collections.Counter(tasks)
27+
max_count = max(counter.values())
28+
min_time = (max_count - 1) * (n + 1) + \
29+
sum(map(lambda c: c == max_count, counter.values()))
3330

3431
return max(min_time, len(tasks))

0 commit comments

Comments
 (0)