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

滑动窗口的最大值

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

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

相关推荐

粉红恶魔派星星:炸了,偶遇kpi面。面试官一直在忙自己的事情。1.手写责任链 2.手写快排 3.linux定时任务的命令 4.springboot的定时任务 5.问了一条实习
今天你投了哪些公司?
点赞 评论 收藏
分享
牛客51274894...:照片认真的吗,找个专门拍证件照的几十块钱整端正点吧,要不就别加照片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务