We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f9fc221 commit ab83c1eCopy full SHA for ab83c1e
longest-common-subsequence/longest-common-subsequence.cpp
@@ -0,0 +1,11 @@
1
+class Solution {
2
+public:
3
+ int longestCommonSubsequence(string &a, string &b) {
4
+ vector<vector<short>> m(a.size() + 1, vector<short>(b.size() + 1));
5
+ for (auto i = 1; i <= a.size(); ++i)
6
+ for (auto j = 1; j <= b.size(); ++j)
7
+ if (a[i - 1] == b[j - 1]) m[i][j] = m[i - 1][j - 1] + 1;
8
+ else m[i][j] = max(m[i - 1][j], m[i][j - 1]);
9
+ return m[a.size()][b.size()];
10
+}
11
+};
0 commit comments