算法1
优先单调队列 $O(n logn)$
C++ 代码
class Solution {
public:
vector<int> maxInWindows(vector<int>& nums, int k) {
int n = nums.size();
priority_queue<pair<int,int>> que;
vector<int> ans;
for (int j = 0; j < n; ++j) {
que.push({nums[j], j});
while (!que.empty() && j - que.top().second + 1 > k) {
que.pop();
}
if (j >= k - 1) {
ans.push_back(que.top().first);
}
}
return ans;
}
};