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 — 最长重复子数组-718 · Issue #114 · sl1673495/leetcode-javascript Open Labels Description给两个整数数组 A 和 B ,返回两个数组中公共的、长度最长的子数组的长度。 说明:
来源:力扣(LeetCode) 思路定义 如果 注意这里我初始化的时候的循环条件都是 /** * @param {number[]} A * @param {number[]} B * @return {number} */ let findLength = function (A, B) { let dp = [] let al = A.length let bl = B.length for (let i = 0; i <= al; i++) { dp[i] = [] for (let j = 0; j <= bl; j++) { dp[i][j] = 0 } } let max = 0 for (let i = al - 1; i >= 0; i--) { for (let j = bl - 1; j >= 0; j--) { let a = A[i] let b = B[j] if (a === b) { dp[i][j] = dp[i + 1][j + 1] + 1 max = Math.max(max, dp[i][j]) } else { dp[i][j] = 0 } } } return max } 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. |