代码拉取完成,页面将自动刷新
<p>Given an array <code>nums</code> of integers, a <em>move</em> consists of choosing any element and <strong>decreasing it by 1</strong>.</p>
<p>An array <code>A</code> is a <em>zigzag array</em> if either:</p>
<ul>
<li>Every even-indexed element is greater than adjacent elements, ie. <code>A[0] > A[1] < A[2] > A[3] < A[4] > ...</code></li>
<li>OR, every odd-indexed element is greater than adjacent elements, ie. <code>A[0] < A[1] > A[2] < A[3] > A[4] < ...</code></li>
</ul>
<p>Return the minimum number of moves to transform the given array <code>nums</code> into a zigzag array.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,2,3]
<strong>Output:</strong> 2
<strong>Explanation:</strong> We can decrease 2 to 0 or 3 to 1.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [9,6,1,6,2]
<strong>Output:</strong> 4
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 1000</code></li>
<li><code>1 <= nums[i] <= 1000</code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。