标签:win i++ size array question subject max public item
64.滑动窗口的最大值
双重循环,算法复杂度为O(nk), k 为窗口大小
1 import java.util.ArrayList; 2 public class Solution { 3 public ArrayList<Integer> maxInWindows(int [] num, int size) 4 { 5 ArrayList<Integer> list = new ArrayList<Integer>(); 6 if(num == null || num.length == 0 || size == 0){ 7 return list; 8 } 9 // 双重循环,算法复杂度为O(nk), k 为窗口大小 10 int max = -1 << 30; 11 for(int i = 0; i < num.length - size + 1; i++){ 12 max = num[i]; 13 for(int j = i + 1; j < num.length && j < i + size; j++){ 14 max = (max > num[j]) ? max : num[j]; 15 } 16 list.add(max); 17 } 18 return list; 19 } 20 }
标签:win i++ size array question subject max public item
原文地址:https://www.cnblogs.com/hi3254014978/p/12669599.html