2294. Partition Array Such That Maximum Difference Is K

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

Содержание

LeetCode problem 2294

class Solution:
    def partitionArray(self, nums: List[int], k: int) -> int:
        nums.sort()
        res, a = 1, nums[0]
        for b in nums:
            if b - a > k:
                a = b
                res += 1
        return res