Skip to content

Commit f35cc91

Browse files
Create LCS
1 parent 86f9a6a commit f35cc91

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Diff for: LCS

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int lcs(string s, string t)
2+
{
3+
int n=s.length();
4+
int m=t.length();
5+
int dp[n+1][m+1];
6+
loopi(n+1)
7+
{
8+
loopj(m+1)
9+
{
10+
if(i==0 || j==0)
11+
dp[i][j]=0;
12+
else if(s[i-1]==t[j-1])
13+
dp[i][j]=1+dp[i-1][j-1];
14+
else
15+
dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
16+
}
17+
}
18+
return dp[n][m];
19+
}

0 commit comments

Comments
 (0)