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

Commit 2dae12c

Browse files
Create LCS_Top_Down.java
1 parent 7a7be24 commit 2dae12c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// solving lcs with top down approch
2+
3+
public class HelloWorld{
4+
5+
public static void main(String []args){
6+
String a = "aeiou";
7+
String b = "asdertiop";
8+
int lena = a.length();
9+
int lenb = b.length();
10+
11+
int[][] arr = new int[lena + 1][lenb + 1];
12+
int i ,j;
13+
for (i =0;i<=lena;i++)
14+
{
15+
for(j =0;j<=lenb;j++)
16+
{
17+
if(i==0 || j == 0)
18+
{
19+
arr[i][j] = 0;
20+
}
21+
}
22+
}
23+
24+
for(i = 1; i<=lena;i++)
25+
{
26+
for (j = 1; j<=lenb; j++)
27+
{
28+
if(a.charAt(i-1) == b.charAt(j-1))
29+
{
30+
arr[i][j] = 1 + arr[i-1][j-1];
31+
}
32+
else
33+
{
34+
arr[i][j] = Math.max(arr[i-1][j] , arr[i][j-1]);
35+
}
36+
}
37+
}
38+
39+
System.out.println(arr[lena][lenb]);
40+
}
41+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /