Class Solution
- java.lang.Object
-
- g2201_2300.s2216_minimum_deletions_to_make_array_beautiful.Solution
-
public class Solution extends Object
2216 - Minimum Deletions to Make Array Beautiful.Medium
You are given a 0-indexed integer array
nums. The arraynumsis beautiful if:nums.lengthis even.nums[i] != nums[i + 1]for alli % 2 == 0.
Note that an empty array is considered beautiful.
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.Return the minimum number of elements to delete from
numsto make it beautiful.Example 1:
Input: nums = [1,1,2,3,5]
Output: 1
Explanation: You can delete either
nums[0]ornums[1]to makenums= [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to makenumsbeautiful.Example 2:
Input: nums = [1,1,2,2,3,3]
Output: 2
Explanation: You can delete
nums[0]andnums[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.Constraints:
1 <= nums.length <= 1050 <= nums[i] <= 105
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intminDeletion(int[] nums)
-