Skip to content

Commit e090c2e

Browse files
authored
Create Solution.java
1 parent 2c019b4 commit e090c2e

File tree

1 file changed

+11
-0
lines changed
  • solution/1144.Decrease Elements To Make Array Zigzag

1 file changed

+11
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public int movesToMakeZigzag(int[] nums) {
3+
int[] res = new int[2];
4+
for (int i = 0, n = nums.length; i < n; ++i) {
5+
int left = i > 0 ? nums[i - 1] : Integer.MAX_VALUE;
6+
int right = i + 1 < n ? nums[i + 1] : Integer.MAX_VALUE;
7+
res[i & 1] += Math.max(0, nums[i] - (Math.min(left, right) - 1));
8+
}
9+
return Math.min(res[0], res[1]);
10+
}
11+
}

0 commit comments

Comments
 (0)