Skip to content

Commit 2f77273

Browse files
authored
Update minimum-initial-energy-to-finish-tasks.cpp
1 parent 6aa0325 commit 2f77273

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

C++/minimum-initial-energy-to-finish-tasks.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Solution {
99
return a[1] - a[0] < b[1] - b[0]; // sort by waste in asc
1010
});
1111
int 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 (const auto& task : tasks) { // we need to pick all the wastes, so greedily to pick the least waste first is always better
1314
result = max(result + task[0], task[1]);
1415
}

0 commit comments

Comments
 (0)