题解 | #滑动窗口最大值#
滑动窗口的最大值
http://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
这道题可以简单粗暴的整俩循环就完事了,拒绝花里胡哨!
import java.util.*;
public class Solution {
public ArrayList<Integer> maxInWindows(int [] num, int size) {
ArrayList<Integer> array = new ArrayList<>();
if(size == 0 || size>num.length || num.length == 0){
return array;
}
for(int i=0;i<num.length-size+1;i++){
int j=i+size;
int temp = num[i];
for(int m=i;m<j;m++){
temp = temp>num[m]?temp:num[m];
}
array.add(temp);
}
return array;
}
}