239. Sliding Window Maximum
2021-06-12 03:06
标签:++ 17. www. solution xsl .com result 最大值 ret https://www.cnblogs.com/grandyang/p/4656517.html 用双端队列实现,最大值在队列首部 239. Sliding Window Maximum 标签:++ 17. www. solution xsl .com result 最大值 ret 原文地址:https://www.cnblogs.com/ymjyqsx/p/10522064.htmlclass Solution {
public:
vectorint> maxSlidingWindow(vectorint>& nums, int k) {
vectorint> result;
dequeint> d;
for(int i = 0;i ){
if(!d.empty() && d.front() == i - k)
d.pop_front();
while(!d.empty() && nums[d.back()] nums[i])
d.pop_back();
d.push_back(i);
if(i - k >= -1)
result.push_back(nums[d.front()]);
}
return result;
}
};
上一篇:C#的datatable使用
下一篇:c++关于使用new的纠正
文章标题:239. Sliding Window Maximum
文章链接:http://soscw.com/index.php/essay/93798.html