package leetcode;

/**
 * https://leetcode.com/problems/decrease-elements-to-make-array-zigzag/
 */
public class Problem1144 {
    public int movesToMakeZigzag(int[] nums) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1144 prob = new Problem1144();
        System.out.println(prob.movesToMakeZigzag(new int[]{1,2,3})); // 2
        System.out.println(prob.movesToMakeZigzag(new int[]{9,6,1,6,2})); // 4
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -205,32 +205,838 @@
     
-// TODO%0A        return 0
+int%5B%5D nums1 = Arrays.copyOf(nums, nums.length);%0A        int min1 = numMoves(nums1, true);%0A        int%5B%5D nums2 = Arrays.copyOf(nums, nums.length);%0A        int min2 = numMoves(nums2, false);%0A        return Integer.min(min1, min2);%0A    %7D%0A%0A    private static int numMoves(int%5B%5D nums, boolean less) %7B%0A        int min = 0;%0A        for (int i = 0; i %3C nums.length - 1; i++) %7B%0A            if (less) %7B // a %3C b%0A                if (nums%5Bi%5D %3E= nums%5Bi + 1%5D) %7B%0A                    min += nums%5Bi%5D - nums%5Bi + 1%5D + 1;%0A                    nums%5Bi + 1%5D = nums%5Bi%5D + 1;%0A                %7D%0A            %7D else %7B // a %3E b%0A                if (nums%5Bi%5D %3C= nums%5Bi + 1%5D) %7B%0A                    min += nums%5Bi + 1%5D - nums%5Bi%5D + 1;%0A                    nums%5Bi + 1%5D = nums%5Bi%5D + 1;%0A                %7D%0A            %7D%0A            less = !less;%0A        %7D%0A        return min
 ;%0A  
@@ -1131,16 +1131,18 @@
 1144();%0A
+//
         
@@ -1208,16 +1208,18 @@
 ); // 2%0A
+//
         
@@ -1289,16 +1289,99 @@
 ); // 4%0A
+        System.out.println(prob.movesToMakeZigzag(new int%5B%5D%7B7,4,8,9,7,7,5%7D)); // 6%0A
     %7D%0A%7D%0A

Update problem 1144