2099. Find Subsequence of Length K With the Largest Sum

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

Содержание

LeetCode problem 2099

class Solution:
    def maxSubsequence(self, nums: List[int], k: int) -> List[int]:
        idx = list(range(len(nums)))
        idx.sort(key=lambda i: nums[i])
        return [nums[i] for i in sorted(idx[-k:])]