We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
来自leetcode300
题目描述: 给定一个未排序的整数数组 nums ,找出数字连续的最长序列(不要求序列元素在原数组中连续)的长度。 请你设计并实现时间复杂度为 O(n) 的算法解决此问题。
示例: 输入:nums = [10,9,2,5,3,7,101,18] 输出:4 解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
输入:nums = [10,9,2,5,3,7,101,18] 输出:4 解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
思路:DP 参考代码
/** * @param {number[]} nums * @return {number} */ var lengthOfLIS = function(nums) { let n = nums.length, res = 0; let f = new Array(n).fill(1) for(let i = 0; i < n; i++) for(let j = 0; j <=i; j++){ if(nums[j] < nums[i]){ f[i] = Math.max(f[i], f[j] + 1) } } for(let i = 0; i < n; i++){ res = Math.max(f[i],res) } return res };
The text was updated successfully, but these errors were encountered:
更新题目来源和参考代码
Sorry, something went wrong.
题目中连续应该改成递增吧
No branches or pull requests
来自leetcode300
示例:
输入:nums = [10,9,2,5,3,7,101,18] 输出:4 解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
思路:DP
参考代码
The text was updated successfully, but these errors were encountered: