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

滑动窗口的最大值

https://www.nowcoder.com/practice/1624bc35a45c42c0bc17d17fa0cba788

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     *
     * @param num int整型一维数组
     * @param size int整型
     * @return int整型一维数组
     */
    public List<int> maxInWindows (List<int> num, int size) {
        // write code here
        if (size == 0 || size > num.Count) return new List<int>();
        List<int> res = new List<int>();
        int left = 0;
        int right = left + size - 1;
        for (; right <= num.Count - 1 ; left++, right++) {
            int max = int.MinValue;
            for (int i = left; i <= right; i++) {
                if (num[i] > max) {
                    max = num[i];
                }
            }
            res.Add(max);
        }
        return res;
    }
}

#滑动窗口双指针问题#
全部评论

相关推荐

05-28 23:26
河南大学 Java
双非本,刚学完Redis,项目只有外卖和点评,八股没准备,算法只有lqb省一,感觉敲的项目也是一言难尽没怎么吸收。怎么你们都有实习了
大牛之途:27急个锤子,你投日常实习最好的时间就是9,10月份,那时候暑期实习都结束了,正是缺人的时候。这份日常又能给你的暑期实习增加竞争力,暑期找的好了秋招也不怕了,都是环环相扣的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务