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
秀哥好,我来提交issue啦,第一次提有点不熟悉。 参考你的dp解法时 nums1 =[1,2,3,2,8] nums2 =[5,6,1,4,7] 这个测试用例会过不了,我的改法是,在你代码对边界判定是否相等的if语句内也加入maxNum = max(maxNum, dp[i][j]);更新最长子树组长度,不过这样改完执行时间和内存都比较高。 if (i == 0 || j == 0) { dp[i][j] = A[i] == B[j] ? 1 : 0; maxNum = max(maxNum, dp[i][j]); } 我的另一种改法是直接在第二重循环内写下: if (nums1[i] == nums2[j]) { if (i == 0 || j == 0) { dp[i][j] = 1; } else { dp[i][j] = dp[i-1][j-1] + 1; } maxNum = max(maxNum, dp[i][j]); }这样会更快一些
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
No branches or pull requests
秀哥好,我来提交issue啦,第一次提有点不熟悉。
参考你的dp解法时
nums1 =[1,2,3,2,8]
nums2 =[5,6,1,4,7]
这个测试用例会过不了,我的改法是,在你代码对边界判定是否相等的if语句内也加入maxNum = max(maxNum, dp[i][j]);更新最长子树组长度,不过这样改完执行时间和内存都比较高。
if (i == 0 || j == 0) {
dp[i][j] = A[i] == B[j] ? 1 : 0;
maxNum = max(maxNum, dp[i][j]);
}
我的另一种改法是直接在第二重循环内写下:
if (nums1[i] == nums2[j]) {
if (i == 0 || j == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = dp[i-1][j-1] + 1;
}
maxNum = max(maxNum, dp[i][j]);
}这样会更快一些
The text was updated successfully, but these errors were encountered: