class Solution {
public int[] maxSlidingWindow(int[] nums, int k) {
LinkedList<Integer> queue = new LinkedList<Integer>();
int[] res = new int[nums.length-k+1];
int left = 0;
for (int i=0;i<nums.length;i++){
if (i>=k){
left++;
}
if (queue.size()>0&&queue.getFirst()<left){
queue.removeFirst();
}
while (queue.size()>0&&nums[queue.getLast()]<=nums[i]){
queue.removeLast();
}
queue.addLast(i);
if (i>=k-1){
res[left]=nums[queue.getFirst()];
}
}
return res;
}
}```
返回滑动窗口中的最大值
最新推荐文章于 2025-03-06 14:59:58 发布
博客围绕滑动窗口求最大值展开,虽无具体内容,但可知核心是解决滑动窗口场景下获取最大值的问题,这在信息技术领域的算法应用中较为常见。
1431

被折叠的 条评论
为什么被折叠?



