import java.util.*;
public class Solution {
public ArrayList<Integer> maxInWindows(int[] num, int size) {
ArrayList<Integer> res = new ArrayList<Integer>();
if (size == 1) {
for (int i = 0; i < num.length; i++) {
res.add(num[i]);
}
return res;
}
if (size > num.length || num.length == 0 || size == 0)
return res;
int n = num.length - size;
for (int i = 0; i < n + 1; i++) {
int max = 0;
int max2 = 0;
for (int j = 0; j < size; j++) {
for (int k = j + 1; k < size; k++) {
max = Math.max(num[i + j], num[i + k]);
if (max > max2) {
max2 = max;
}
}
}
res.add(max2);
}
return res;
}
}
数组解决滑动窗口最大值问题
最新推荐文章于 2022-04-01 01:44:21 发布