题解 | #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
let step = null;
while ((line = await readline())) {
if (!step) {
step = line;
} else {
getMax(line.split(" ").map(Number));
}
}
})();
function getMax(arr) {
let dp = arr.map(() => {
return 1;
});
for (let i = 1; i < arr.length; i++) {
let max = 1
for (let j = 0; j < i; j++) {
if (arr[i] > arr[j]) {
max = Math.max(max, dp[j] + 1);
}
}
dp[i] = max;
}
console.log(Math.max(...dp));
}
遍历每个节点,获取以此节点为结尾的,可递增的最大数量,存入新数组中对应的位置。最后比较新数组中最大的数字,即为结果

联想公司福利 1543人发布