mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> 。你需要找到 <code>nums</code> 中长度为 <code>k</code> 的 <strong>子序列</strong> ,且这个子序列的 <strong>和最大 </strong>。</p>
 | 
						||
 | 
						||
<p>请你返回 <strong>任意</strong> 一个长度为 <code>k</code> 的整数子序列。</p>
 | 
						||
 | 
						||
<p><strong>子序列</strong> 定义为从一个数组里删除一些元素后,不改变剩下元素的顺序得到的数组。</p>
 | 
						||
 | 
						||
<p> </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> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 1000</code></li>
 | 
						||
	<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li>
 | 
						||
	<li><code>1 <= k <= nums.length</code></li>
 | 
						||
</ul>
 |