string LCS(string str1, string str2) {
// write code here
int m = str1.size(), n = str2.size();
string res;
int len = 0;
int index = 0;
vector<vector<int>> dp(m + 1, vector<int>(n + 1));
for (int i = 0; i < m; ++i)
{
for (int j = 0; j < n; ++j)
{
if (str1[i] == str2[j])
{
dp[i + 1][j + 1] = 1 + dp[i][j];
if (dp[i + 1][j + 1] > len)
{
len = dp[i + 1][j + 1];
index = i;
}
}
}
}
return str1.substr(index - len + 1, len);
}
12-31
10-26
1030
10-04
1万+
04-08
448
07-24
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交