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 fe0a02f commit b0fbfbfCopy full SHA for b0fbfbf
longest-common-subsequence/PDKhan.cpp
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public:
3
+ int longestCommonSubsequence(string text1, string text2) {
4
+ int t1_len = text1.length();
5
+ int t2_len = text2.length();
6
+ vector<vector<int>> dp(t1_len + 1, vector(t2_len + 1, 0));
7
+
8
+ for(int i = 1; i <= t1_len; i++){
9
+ for(int j = 1; j <= t2_len; j++){
10
+ if(text1[i-1] == text2[j-1])
11
+ dp[i][j] = dp[i-1][j-1] + 1;
12
+ else
13
+ dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
14
+ }
15
16
17
+ return dp[t1_len][t2_len];
18
19
+ };
0 commit comments