1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/找到和最大的长度为 K 的子序列 [find-subsequence-of-length-k-with-the-largest-sum].html
2022-03-29 12:43:11 +08:00

42 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;。你需要找到&nbsp;<code>nums</code>&nbsp;中长度为 <code>k</code>&nbsp;<strong>子序列</strong>&nbsp;,且这个子序列的&nbsp;<strong>和最大&nbsp;</strong></p>
<p>请你返回 <strong>任意</strong> 一个长度为&nbsp;<code>k</code>&nbsp;的整数子序列。</p>
<p><strong>子序列</strong>&nbsp;定义为从一个数组里删除一些元素后,不改变剩下元素的顺序得到的数组。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [2,1,3,3], k = 2
<b>输出:</b>[3,3]
<strong>解释:</strong>
子序列有最大和3 + 3 = 6 。</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [-1,-2,3,4], k = 3
<b>输出:</b>[-1,3,4]
<b>解释:</b>
子序列有最大和:-1 + 3 + 4 = 6 。
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums = [3,4,3,3], k = 2
<b>输出:</b>[3,4]
<strong>解释:</strong>
子序列有最大和3 + 4 = 7 。
另一个可行的子序列为 [4, 3] 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>-10<sup>5</sup>&nbsp;&lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= k &lt;= nums.length</code></li>
</ul>