Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9673f8b

Browse files
authored
Merge pull requestneetcode-gh#999 from agnihotriketan/patch-4
C# 1143-Longest-Common-Subsequence.cs
2 parents117a1d9 +b1d0e6e commit9673f8b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
publicclassSolution{
2+
publicintLongestCommonSubsequence(stringtext1,stringtext2){
3+
int[,]dp=newint[text1.Length+1,text2.Length+1];
4+
for(inti=0;i<text1.Length+1;i++)
5+
{
6+
for(intj=0;j<text2.Length+1;j++)
7+
{
8+
dp[i,j]=0;
9+
}
10+
}
11+
for(inti=text1.Length-1;i>=0;i--)
12+
{
13+
for(intj=text2.Length-1;j>=0;j--)
14+
{
15+
if(text1[i]==text2[j])
16+
dp[i,j]=1+dp[i+1,j+1];
17+
else
18+
dp[i,j]=Math.Max(dp[i,j+1],dp[i+1,j]);
19+
}
20+
}
21+
returndp[0,0];
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp