1665. Minimum Initial Energy to Finish Tasks

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1665

class Solution:
    def minimumEffort(self, tasks: List[List[int]]) -> int:
        res = cur = 0
        for a, m in sorted(tasks, key=lambda x: x[0] - x[1]):
            if cur < m:
                res += m - cur
                cur = m
            cur -= a
        return res