国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

LeetCode 2099. Find Subsequence of Length K With the Largest Sum

2023-02-24 13:48 作者:您是打尖兒還是住店呢  | 我要投稿


You are given an integer array?nums?and an integer?k. You want to find a?subsequence?of?nums?of length?k?that has the?largest?sum.

Return?any?such subsequence as an integer array of length?k.

A?subsequence?is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

?

Example 1:

Input: nums = [2,1,3,3], k = 2Output: [3,3]Explanation:The subsequence has the largest sum of 3 + 3 = 6.

Example 2:

Input: nums = [-1,-2,3,4], k = 3Output: [-1,3,4]Explanation: The subsequence has the largest sum of -1 + 3 + 4 = 6.

Example 3:

Input: nums = [3,4,3,3], k = 2Output: [3,4]Explanation:The subsequence has the largest sum of 3 + 4 = 7. Another possible subsequence is [4, 3].

?

Constraints:

  • 1 <= nums.length <= 1000

  • -105?<= nums[i] <= 105

  • 1 <= k <= nums.length

  • Easy題目,沒辦法要保證輸出的數(shù)組順序跟原來的順序是一樣的就只能優(yōu)先隊(duì)列去排序,list刪除優(yōu)先隊(duì)列刪除的元素,最后去輸出數(shù)組,



Runtime:?11 ms, faster than?39.79%?of?Java?online submissions for?Find Subsequence of Length K With the Largest Sum.

Memory Usage:?42.8 MB, less than?15.79%?of?Java?online submissions for?Find Subsequence of Length K With the Largest Sum.


LeetCode 2099. Find Subsequence of Length K With the Largest Sum的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
南昌市| 连南| 东明县| 赣州市| 同心县| 辰溪县| 什邡市| 色达县| 潞西市| 昭苏县| 西乌| 阜康市| 正宁县| 海晏县| 平罗县| 东乡族自治县| 和平县| 翁源县| 威海市| 温州市| 鄂托克旗| 涞源县| 台东县| 曲水县| 涪陵区| 山东省| 镶黄旗| 青海省| 崇信县| 舟曲县| 重庆市| 获嘉县| 沁水县| 宾川县| 道真| 浏阳市| 海林市| 昌平区| 廉江市| 观塘区| 邵武市|