标签:++ 17. www. solution xsl .com result 最大值 ret
https://www.cnblogs.com/grandyang/p/4656517.html
用双端队列实现,最大值在队列首部
class Solution { public: vector<int> maxSlidingWindow(vector<int>& nums, int k) { vector<int> result; deque<int> d; for(int i = 0;i < nums.size();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; } };
标签:++ 17. www. solution xsl .com result 最大值 ret
原文地址:https://www.cnblogs.com/ymjyqsx/p/10522064.html