2216. Minimum Deletions to Make Array Beautiful Medium

@problem@discussion
#Array#Stack#Greedy



1/**
2 * [2216] Minimum Deletions to Make Array Beautiful
3 *
4 * You are given a 0-indexed integer array nums. The array nums is beautiful if:
5 * 
6 * 	nums.length is even.
7 * 	nums[i] != nums[i + 1] for all i % 2 == 0.
8 * 
9 * Note that an empty array is considered beautiful.
10 * You can delete any number of elements from nums. When you delete an element, all the elements to the right of the deleted element will be shifted one unit to the left to fill the gap created and all the elements to the left of the deleted element will remain unchanged.
11 * Return the minimum number of elements to delete from nums to make it beautiful.
12 *  
13 * Example 1:
14 * 
15 * Input: nums = [1,1,2,3,5]
16 * Output: 1
17 * Explanation: You can delete either nums[0] or nums[1] to make nums = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make nums beautiful.
18 * 
19 * Example 2:
20 * 
21 * Input: nums = [1,1,2,2,3,3]
22 * Output: 2
23 * Explanation: You can delete nums[0] and nums[5] to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= nums.length <= 10^5
29 * 	0 <= nums[i] <= 10^5
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/minimum-deletions-to-make-array-beautiful/
35// discuss: https://leetcode.com/problems/minimum-deletions-to-make-array-beautiful/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn min_deletion(nums: Vec<i32>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_2216() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.