Skip to content

Commit 951bc09

Browse files
authored
Create [13]_1.java
1 parent 32fef6c commit 951bc09

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Solutions/[13]_1.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.Scanner;
2+
3+
public class Main {
4+
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
8+
String x = sc.nextLine();
9+
String y = sc.nextLine();
10+
int[][] dp = new int[1001][1001];
11+
12+
for (int i = 1; i <= x.length(); i++) {
13+
for (int j = 1; j <= y.length(); j++) {
14+
if (x.charAt(i - 1) == y.charAt(j - 1)) {
15+
dp[i][j] = dp[i - 1][j - 1] + 1;
16+
}
17+
else {
18+
dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]);
19+
}
20+
}
21+
}
22+
23+
System.out.println(dp[x.length()][y.length()]);
24+
}
25+
26+
}

0 commit comments

Comments
 (0)