2966. Divide Array Into Arrays With Max Difference

2966. Divide Array Into Arrays With Max Difference

class Solution:
    def divideArray(self, nums: List[int], k: int) -> List[List[int]]:
        if len(nums)%3!=0:
            return []
        
        nums.sort()

        results=[]
        for i in range(0,len(nums),3):
            if nums[i+2]-nums[i]>k:return []
            results.append(nums[i:i+3])
        return results 
            

你可能感兴趣的:(leetcode)