1403. Minimum Subsequence in Non-Increasing Order

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1403

class Solution:
    def minSubsequence(self, nums: List[int]) -> List[int]:
        res = []
        s, t = sum(nums), 0
        for x in sorted(nums, reverse=True):
            t += x
            res.append(x)
            if t > s - t:
                break
        return res