简单题中的简单题,思路真的太明显了
class Solution(object):
def minimumDifference(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
排序+滑动窗口
"""
nums.sort()
ans=nums[k-1]-nums[0]
for i in range(k-1,len(nums)):
ans=min(ans,nums[i]-nums[i-k+1])
return ans