题解 | #滑动窗口的最大值#
滑动窗口的最大值
https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788
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 ArrayList<Integer> result = new ArrayList(); if(num.length<size) return result; if(size==0) return result; int left =0; int right = left+size; while(right<=num.length){ int temp =Integer.MIN_VALUE; for(int j=left;j<right;j++){ temp = Math.max(temp,num[j]); } result.add(temp); temp=Integer.MIN_VALUE; left++; right++; } return result; } }#刷题努力下##java#