五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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ó)家法律
霍林郭勒市| 清苑县| 赞皇县| 伊金霍洛旗| 醴陵市| 洮南市| 英超| 襄垣县| 浦东新区| 长治县| 辽源市| 前郭尔| 广南县| 大姚县| 申扎县| 志丹县| 青海省| 兰考县| 大同县| 新郑市| 前郭尔| 通化市| 章丘市| 凤山市| 潮州市| 抚宁县| 当阳市| 贡山| 滨州市| 陇南市| 高邮市| 巫溪县| 郯城县| 临沂市| 东乌| 喜德县| 高雄县| 六安市| 香港| 安乡县| 保山市|