最长递增子序列 动态规划
给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。
子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。
example:
输入:nums = [10,9,2,5,3,7,101,18]
输出:4
解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
var lengthOfLIS = function(nums) {
if(nums.length <= 1) return nums.length
let dp = []
let len = nums.length
for(let i=0,l = nums.length;i nums[j]) //条件为递增
{
dp[i] = Math.max(dp[i],dp[j]+1)
}
}
//更新res 最长子序列长度
// 每一层内层循环 更新res
if(dp[i] > res){
res = dp[i]
}
}
return res
};