class Solution {
public:
vector<int> maxSlidingWindow(vector<int>& nums, int k) {
deque<int> q;
vector<int> res;
for(int i=0;i<nums.size();i++)
{
//删除滑出窗口的元素
while(q.size()&&i-q.front()>=k) q.pop_front();
//插入新元素
while(q.size()&&nums[q.back()]<=nums[i])
q.pop_back();
q.push_back(i);
if(i>=k-1)
res.push_back(nums[q.front()]);
}
return res;
}
};
标签:nums,int,res,最大值,back,vector,239,LeetCode
From: https://www.cnblogs.com/tangxibomb/p/17553416.html