题解 | #Redraiment的走法#

Redraiment的走法

https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

// 最长单调递增序列

void async function () {
    // Write your code here
    const n = await readline();
    const datas = (await readline()).split(' ').filter(i => i).map(i => parseInt(i));
    if (parseInt(n) != datas.length) {
        throw new Error('非法输入')
    }
    const num = maxLong(datas)
    console.log(num)
}()

// f(n) = f(i) + 1, i < n 
function maxLong(datas) {
    let maxLongs = [];
    let max = 0;
    for (let i = 0; i < datas.length; i++) {
        maxLongs[i] = 1;        
        for (j = 0; j < i; j++) {
            if (datas[j] < datas[i]) {
                maxLongs[i] = Math.max(maxLongs[j] + 1, maxLongs[i]);
            }
        }
        max = max < maxLongs[i] ? maxLongs[i] : max;
    }
    return max;
}

全部评论

相关推荐

身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
小浪_coder:深圳除了一些计算机,UI设计,金融类等一些可以月薪过万的工作之外, 认识很多朋友做运营,营销,文员的工作, 月薪基本都在4-6K左右,还有大把人在干
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 11:30
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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