GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — 最长上升子序列-300 · Issue #83 · sl1673495/leetcode-javascript Open Labels Description给定一个无序的整数数组,找到其中最长上升子序列的长度。 示例: 可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。 https://leetcode-cn.com/problems/longest-increasing-subsequence 思路从前往后求解,对于每个值 只要 最后从 /** * @param {number[]} nums * @return {number} */ let lengthOfLIS = function (nums) { let dp = [] let n = nums.length if (!n) { return 0 } dp[0] = 1 for (let i = 1; i < n; i++) { let num = nums[i] let max = 1 // j 从 [0, i) 依次求出可以和 i 组成的最长上升子序列 for (let j = 0; j < i; j++) { let prevNum = nums[j] if (num > prevNum) { // 循环中不断更新 max 值 max = Math.max(max, dp[j] + 1) } } dp[i] = max } return Math.max(...dp) } ActivityMetadataMetadataAssigneesLabelsProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |