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
https://leetcode-cn.com/problems/longest-arithmetic-sequence/
/** * @param {number[]} A * @return {number} */ var longestArithSeqLength = function(A) { if (A.length <= 2) { return A.length; } const dp = {}; function get(x, y) { return dp[x] && dp[x][y]; } function set(x, y, value) { dp[x] = dp[x] || {}; dp[x][y] = value; } let max = 2; for (let i = 1; i < A.length; i++) { for (let j = 0; j < i; j++) { const diff = A[i] - A[j]; if (get(j, diff)) { set(i, diff, Math.max( get(i, diff) || 0, get(j, diff) + 1 )); } if (!get(i, diff)) { set(i, diff, 2); } max = Math.max(max, get(i, diff)); } } return max; };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
https://leetcode-cn.com/problems/longest-arithmetic-sequence/
思路
代码
The text was updated successfully, but these errors were encountered: