Guest User

Solution | 1665. Minimum Initial Energy to Finish Tasks | @silvermete0r

a guest
May 12th, 2026
17
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | Source Code | 0 0
  1. # https://leetcode.com/problems/minimum-initial-energy-to-finish-tasks/
  2.  
  3. class Solution:
  4.     def minimumEffort(self, tasks: List[List[int]]) -> int:
  5.         tasks.sort(key=lambda x: -(x[1] - x[0]))
  6.         have = tasks[0][1]
  7.         ans = tasks[0][1]
  8.         for i in range(1, len(tasks)):
  9.             have -= tasks[i-1][0]
  10.             if have < tasks[i][1]:
  11.                 ans += (tasks[i][1] - have)
  12.                 have = tasks[i][1]
  13.         return ans
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment