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-alternating-subsequence-sum].html
2022-03-29 12:43:11 +08:00

45 lines
1.7 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>一个下标从 <strong>0</strong> 开始的数组的 <strong>交替和</strong> 定义为 <strong>偶数</strong> 下标处元素之 <strong></strong> 减去 <strong>奇数</strong> 下标处元素之 <strong></strong> 。</p>
<ul>
<li>比方说,数组 <code>[4,2,5,3]</code> 的交替和为 <code>(4 + 5) - (2 + 3) = 4</code> 。</li>
</ul>
<p>给你一个数组 <code>nums</code> ,请你返回 <code>nums</code> 中任意子序列的 <strong>最大交替和</strong> (子序列的下标 <strong>重新</strong> 从 0 开始编号)。</p>
<ul>
</ul>
<p>一个数组的 <strong>子序列</strong> 是从原数组中删除一些元素后(也可能一个也不删除)剩余元素不改变顺序组成的数组。比方说,<code>[2,7,4]</code> 是 <code>[4,<strong>2</strong>,3,<strong>7</strong>,2,1,<strong>4</strong>]</code> 的一个子序列(加粗元素),但是 <code>[2,4,2]</code> 不是。</p>
<p> </p>
<p><b>示例 1</b></p>
<pre><b>输入:</b>nums = [<strong>4</strong>,<strong>2</strong>,<strong>5</strong>,3]
<b>输出:</b>7
<b>解释:</b>最优子序列为 [4,2,5] ,交替和为 (4 + 5) - 2 = 7 。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [5,6,7,<strong>8</strong>]
<b>输出:</b>8
<b>解释:</b>最优子序列为 [8] ,交替和为 8 。
</pre>
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums = [<strong>6</strong>,2,<strong>1</strong>,2,4,<strong>5</strong>]
<b>输出:</b>10
<b>解释:</b>最优子序列为 [6,1,5] ,交替和为 (6 + 5) - 1 = 10 。
</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;= 10<sup>5</sup></code></li>
</ul>