Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/
- class Solution:
- def minimumEffort(self, tasks: List[List[int]]) -> int:
- tasks.sort(key=lambda x: -(x[1] - x[0]))
- have = tasks[0][1]
- ans = tasks[0][1]
- for i in range(1, len(tasks)):
- have -= tasks[i-1][0]
- if have < tasks[i][1]:
- ans += (tasks[i][1] - have)
- have = tasks[i][1]
- return ans
Advertisement