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

滑动窗口的最大值

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

function maxInWindows(num, size)
{
    // write code here
    if(num.length < size || size == 0){
        return [];
    }
    let res = []
    let i = 0;
    while(i <= num.length - size){
        let max = -100000
        for(let j = i;j<i+size;j++){
            if(num[j] > max){
                max = num[j];
            }
        }
        i += 1;
        res.push(max);
    }
    return res;
}
module.exports = {
    maxInWindows : maxInWindows
};

#我的实习求职记录#
全部评论

相关推荐

今天 19:05
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务