java.lang.Object
g1101_1200.s1144_decrease_elements_to_make_array_zigzag.Solution

public class Solution extends Object
1144 - Decrease Elements To Make Array Zigzag.<p>Medium</p> <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><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,3]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> We can decrease 2 to 0 or 3 to 1.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [9,6,1,6,2]</p> <p><strong>Output:</strong> 4</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1000</code></li> <li><code>1 <= nums[i] <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • movesToMakeZigzag

      public int movesToMakeZigzag(int[] nums)