Skip to content

Commit 6aa0325

Browse files
authored
Update minimum-initial-energy-to-finish-tasks.py
1 parent 976bbf0 commit 6aa0325

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Python/minimum-initial-energy-to-finish-tasks.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def minimumEffort(self, tasks):
99
"""
1010
tasks.sort(key=lambda x: x[1]-x[0]) # sort by waste in asc
1111
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
1213
for a, m in tasks: # we need to pick all the wastes, so greedily to pick the least waste first is always better
1314
result = max(result+a, m)
1415
return result

0 commit comments

Comments
 (0)