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)/递减元素使数组呈锯齿状 [decrease-elements-to-make-array-zigzag].html
2022-03-29 12:43:11 +08:00

35 lines
1.2 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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>给你一个整数数组&nbsp;<code>nums</code>,每次 <strong>操作</strong>&nbsp;会从中选择一个元素并 <strong>将该元素的值减少&nbsp;1</strong></p>
<p>如果符合下列情况之一,则数组&nbsp;<code>A</code>&nbsp;就是 <strong>锯齿数组</strong></p>
<ul>
<li>每个偶数索引对应的元素都大于相邻的元素,即&nbsp;<code>A[0] &gt; A[1] &lt; A[2] &gt; A[3] &lt; A[4] &gt; ...</code></li>
<li>或者,每个奇数索引对应的元素都大于相邻的元素,即&nbsp;<code>A[0] &lt; A[1] &gt; A[2] &lt; A[3] &gt; A[4] &lt; ...</code></li>
</ul>
<p>返回将数组&nbsp;<code>nums</code>&nbsp;转换为锯齿数组所需的最小操作次数。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>nums = [1,2,3]
<strong>输出:</strong>2
<strong>解释:</strong>我们可以把 2 递减到 0或把 3 递减到 1。
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>nums = [9,6,1,6,2]
<strong>输出:</strong>4
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
</ul>