2216. Minimum Deletions to Make Array Beautiful

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2216

class Solution:
    def minDeletion(self, nums: List[int]) -> int:
        n = len(nums)
        res = i = 0
        while i < n:
            j = i + 1
            while j < n and nums[j] == nums[i]:
                j += 1
                res += 1
            i = j + 1
        res += (n - res) % 2
        return res