2009. Minimum Number of Operations to Make Array Continuous

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

Содержание

LeetCode problem 2009

class Solution:
    def minOperations(self, nums: List[int]) -> int:
        n = len(nums)
        nums = sorted(set(nums))
        res, j = n, 0
        for i, v in enumerate(nums):
            while j < len(nums) and nums[j] - v <= n - 1:
                j += 1
            res = min(res, n - (j - i))
        return res