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)/好子数组的最大分数 [maximum-score-of-a-good-subarray].html
2022-03-29 12:43:11 +08:00

32 lines
1.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给你一个整数数组 <code>nums</code> <strong>(下标从 0 开始)</strong>和一个整数 <code>k</code> 。</p>
<p>一个子数组 <code>(i, j)</code> 的 <strong>分数</strong> 定义为 <code>min(nums[i], nums[i+1], ..., nums[j]) * (j - i + 1)</code> 。一个 <strong></strong> 子数组的两个端点下标需要满足 <code>i &lt;= k &lt;= j</code> 。</p>
<p>请你返回 <strong></strong> 子数组的最大可能 <strong>分数</strong> 。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [1,4,3,7,4,5], k = 3
<b>输出:</b>15
<b>解释:</b>最优子数组的左右端点下标是 (1, 5) ,分数为 min(4,3,7,4,5) * (5-1+1) = 3 * 5 = 15 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [5,5,4,5,4,1,1,1], k = 0
<b>输出:</b>20
<b>解释:</b>最优子数组的左右端点下标是 (0, 4) ,分数为 min(5,5,4,5,4) * (4-0+1) = 4 * 5 = 20 。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 2 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= k &lt; nums.length</code></li>
</ul>