1403. Minimum Subsequence in Non-Increasing Order
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 73% Topics: Array, Greedy, Sorting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogn)
# Space: O(1)
class Solution(object):
def minSubsequence(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
result, total, curr = [], sum(nums), 0
nums.sort(reverse=True)
for i, x in enumerate(nums):
curr += x
if curr > total-curr:
break
return nums[:i+1]
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions