We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 976bbf0 commit 6aa0325Copy full SHA for 6aa0325
Python/minimum-initial-energy-to-finish-tasks.py
@@ -9,6 +9,7 @@ def minimumEffort(self, tasks):
9
"""
10
tasks.sort(key=lambda x: x[1]-x[0]) # sort by waste in asc
11
result = 0
12
+ # you can see proof here, https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/discuss/944633/Explanation-on-why-sort-by-difference
13
for a, m in tasks: # we need to pick all the wastes, so greedily to pick the least waste first is always better
14
result = max(result+a, m)
15
return result
0 commit comments