最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(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ó)家法律
苏尼特右旗| SHOW| 观塘区| 揭东县| 新干县| 朝阳区| 葫芦岛市| 建阳市| 莒南县| 阳原县| 文安县| 北辰区| 石林| 甘肃省| 永新县| 福建省| 海宁市| 凌海市| 敖汉旗| 龙游县| 望都县| 南郑县| 简阳市| 铜鼓县| 依安县| 庆阳市| 花垣县| 隆化县| 南木林县| 灵川县| 五大连池市| 揭东县| 沧源| 珠海市| 大城县| 怀宁县| 临夏县| 潜山县| 福州市| 遂川县| 桐庐县|