一、 大小固定的滑动窗口
- 例题:
解答:
class Solution {
public:
int minimumDifference(vector<int>& nums, int k) {
int n = nums.size();
sort(nums.begin(), nums.end());
int ans = INT_MAX;
for (int i = 0; i + k - 1 < n; ++i) {
ans = min(ans, nums[i + k - 1] - nums[i]);
}
return ans;
}
};
标签:窗口,nums,int,问题,ans,滑动,例题
From: https://www.cnblogs.com/zh-Note/p/17131734.html