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

滑动窗口的最大值

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

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

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务