1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/翻转子数组得到最大的数组值 [reverse-subarray-to-maximize-array-value].html

30 lines
971 B
HTML
Raw Normal View History

2022-03-27 20:37:52 +08:00
<p>给你一个整数数组&nbsp;<code>nums</code> 。「数组值」定义为所有满足&nbsp;<code>0 &lt;= i &lt; nums.length-1</code>&nbsp;&nbsp;<code>|nums[i]-nums[i+1]|</code>&nbsp;的和。</p>
<p>你可以选择给定数组的任意子数组,并将该子数组翻转。但你只能执行这个操作&nbsp;<strong>一次</strong></p>
<p>请你找到可行的最大 <strong>数组值&nbsp;</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [2,3,1,5,4]
<strong>输出:</strong>10
<strong>解释:</strong>通过翻转子数组 [3,1,5] ,数组变成 [2,5,1,3,4] ,数组值为 10 。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [2,4,9,24,2,1,10]
<strong>输出:</strong>68
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 3*10^4</code></li>
<li><code>-10^5 &lt;= nums[i] &lt;= 10^5</code></li>
</ul>