题解 | #滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
import java.util.*; public class Solution { public ArrayList<Integer> maxInWindows (int[] num, int size) { int i = 0; int j = 0; int max = 0; ArrayList<Integer> arr = new ArrayList<>(); if (num.length<size||size==0) return new ArrayList<Integer>(); for (int index = 0;index< num.length-size+1;index++) { max = num[i]; while (i<size+j-1){ i++; if (max<num[i]){ max = num[i]; } } j++; arr.add(max); i = j; } return arr; } }