题解 | #滑动窗口的最大值#

滑动窗口的最大值

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;
    }
}

全部评论

相关推荐

zhiyog:哈哈哈,其实是津巴布韦币
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务