1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-03-14 16:22:24 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/两个非重叠子数组的最大和 [maximum-sum-of-two-non-overlapping-subarrays].html

43 lines
1.6 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>给你一个整数数组 <code>nums</code> 和两个整数 <code>firstLen</code><code>secondLen</code>,请你找出并返回两个非重叠<strong> 子数组 </strong>中元素的最大和<em></em>长度分别为 <code>firstLen</code><code>secondLen</code></p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>长度为 <code>firstLen</code> 的子数组可以出现在长为 <code>secondLen</code> 的子数组之前或之后,但二者必须是不重叠的。</p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>子数组是数组的一个 <strong>连续</strong> 部分。</p>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
2023-12-09 18:42:21 +08:00
<strong>输入:</strong>nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2
2022-03-27 20:46:41 +08:00
<strong>输出:</strong>20
<strong>解释:</strong>子数组的一种选择中,[9] 长度为 1[6,5] 长度为 2。
</pre>
<p><strong>示例 2</strong></p>
<pre>
2023-12-09 18:42:21 +08:00
<strong>输入:</strong>nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2
2022-03-27 20:46:41 +08:00
<strong>输出:</strong>29
<strong>解释:</strong>子数组的一种选择中,[3,8,1] 长度为 3[8,9] 长度为 2。
</pre>
<p><strong>示例 3</strong></p>
<pre>
2023-12-09 18:42:21 +08:00
<strong>输入:</strong>nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3
2022-03-27 20:46:41 +08:00
<strong>输出:</strong>31
2023-12-09 18:42:21 +08:00
<strong>解释:</strong>子数组的一种选择中,[5,6,0,9] 长度为 4[0,3,8] 长度为 3。
</pre>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<li><code>1 &lt;= firstLen, secondLen &lt;= 1000</code></li>
<li><code>2 &lt;= firstLen + secondLen &lt;= 1000</code></li>
<li><code>firstLen + secondLen &lt;= nums.length &lt;= 1000</code></li>
<li><code>0 &lt;= nums[i] &lt;= 1000</code></li>
2022-03-27 20:46:41 +08:00
</ul>