1144. Decrease Elements To Make Array Zigzag Medium

@problem@discussion
#Array#Greedy



1/**
2 * [1144] Decrease Elements To Make Array Zigzag
3 *
4 * Given an array nums of integers, a move consists of choosing any element and decreasing it by 1.
5 * An array A is a zigzag array if either:
6 * 
7 * 	Every even-indexed element is greater than adjacent elements, ie. A[0] > A[1] < A[2] > A[3] < A[4] > ...
8 * 	OR, every odd-indexed element is greater than adjacent elements, ie. A[0] < A[1] > A[2] < A[3] > A[4] < ...
9 * 
10 * Return the minimum number of moves to transform the given array nums into a zigzag array.
11 *  
12 * Example 1:
13 * 
14 * Input: nums = [1,2,3]
15 * Output: 2
16 * Explanation: We can decrease 2 to 0 or 3 to 1.
17 * 
18 * Example 2:
19 * 
20 * Input: nums = [9,6,1,6,2]
21 * Output: 4
22 * 
23 *  
24 * Constraints:
25 * 
26 * 	1 <= nums.length <= 1000
27 * 	1 <= nums[i] <= 1000
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/decrease-elements-to-make-array-zigzag/
33// discuss: https://leetcode.com/problems/decrease-elements-to-make-array-zigzag/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn moves_to_make_zigzag(nums: Vec<i32>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_1144() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.