Skip to content

Commit ab83c1e

Browse files
Time: 43 ms (13.07%), Space: 10 MB (93.87%) - LeetHub
1 parent f9fc221 commit ab83c1e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)