题解 | #最长公共子串#
最长公共子串
http://www.nowcoder.com/practice/f33f5adc55f444baa0e0ca87ad8a6aac
思路:状态方程P:d[i][j] = d[i-1][j-1] +1
if(str1[i] == str2[j]){
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j+1] = 0;
}
//用于最后字符串切割的函数
if (dp[i + 1][j + 1] > maxLenth) {
maxLenth = dp[i + 1][j+1];
maxEndIndex = {i,j};
}
str1.substr(maxEndIndex[0] - maxLenth + 1, maxLenth)