1101-1110¶
1111-1120¶
1143.最长公共子序列¶
class Solution {
public:
int longestCommonSubsequence(string text1, string text2) {
const int N = text1.size(), M = text2.size();
vector <vector<int>> f(N + 1, vector<int>(M + 1, 0));
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= M; ++j) {
if (text1[i - 1] == text2[j - 1]) f[i][j] = f[i - 1][j - 1] + 1;
else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
}
}
return f[N][M];
}
};