import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param num int整型一维数组
* @param size int整型
* @return int整型ArrayList
*/
public ArrayList<Integer> maxInWindows (int[] num, int size) {
// write code here
if (num == null || size > num.length || size == 0) {
return new ArrayList<>();
}
// 结果集
ArrayList<Integer> result = new ArrayList<>();
// 滑动窗口的开始位置
int left = 0;
int right = size - 1;
while (right < num.length) {
// 滑动窗口中的最大值
int max = Integer.MIN_VALUE;
while (left <= right) {
max = Math.max(max, num[left]);
left ++;
}
result.add(max);
// 窗口的结束位置向左移动
right ++;
// 开始位置向左移动
left = right - size + 1;
}
return result;
}
}