Class Solution
java.lang.Object
g2201_2300.s2216_minimum_deletions_to_make_array_beautiful.Solution
2216 - Minimum Deletions to Make Array Beautiful.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. The array <code>nums</code> is <strong>beautiful</strong> if:</p>
<ul>
<li><code>nums.length</code> is even.</li>
<li><code>nums[i] != nums[i + 1]</code> for all <code>i % 2 == 0</code>.</li>
</ul>
<p>Note that an empty array is considered beautiful.</p>
<p>You can delete any number of elements from <code>nums</code>. When you delete an element, all the elements to the right of the deleted element will be <strong>shifted one unit to the left</strong> to fill the gap created and all the elements to the left of the deleted element will remain <strong>unchanged</strong>.</p>
<p>Return <em>the <strong>minimum</strong> number of elements to delete from</em> <code>nums</code> <em>to make it</em> <em>beautiful.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,1,2,3,5]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> You can delete either <code>nums[0]</code> or <code>nums[1]</code> to make <code>nums</code> = [1,2,3,5] which is beautiful. It can be proven you need at least 1 deletion to make <code>nums</code> beautiful.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [1,1,2,2,3,3]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> You can delete <code>nums[0]</code> and <code>nums[5]</code> to make nums = [1,2,2,3] which is beautiful. It can be proven you need at least 2 deletions to make nums beautiful.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
<li><code>0 <= nums[i] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minDeletion
public int minDeletion(int[] nums)
-