2216. Minimum Deletions to Make Array Beautiful

Обновлено: 2024-03-12
1 мин
[]

Содержание

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