18 lines
No EOL
474 B
Python
18 lines
No EOL
474 B
Python
# https://leetcode.com/problems/partition-array-such-that-maximum-difference-is-k
|
|
|
|
from typing import List
|
|
|
|
class Solution:
|
|
def partitionArray(self, nums: List[int], k: int) -> int:
|
|
nums.sort()
|
|
left = 0
|
|
right = 0
|
|
result = 0
|
|
while right < len(nums):
|
|
if nums[left] + k < nums[right]:
|
|
left = right
|
|
result += 1
|
|
else:
|
|
right += 1
|
|
return result + 1
|
|
|