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.
2 parents fe4cdc0 + 89a2b60 commit 8c01edbCopy full SHA for 8c01edb
LiiNi-coder/202510/01 BOJ LCS.md
@@ -0,0 +1,27 @@
1
+```java
2
+import java.io.*;
3
+import java.util.*;
4
+
5
+public class Main {
6
+ public static void main(String[] args) throws IOException {
7
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8
+ String A = br.readLine();
9
+ String B = br.readLine();
10
+ int n = A.length();
11
+ int m = B.length();
12
13
+ int[][] dp = new int[n + 1][m + 1];
14
+ for(int i = 1; i <= n; i++) {
15
+ for(int j = 1; j <= m; j++) {
16
+ if(A.charAt(i - 1) == B.charAt(j - 1)) {
17
+ dp[i][j] = dp[i-1][j-1] + 1;
18
+ } else {
19
+ dp[i][j] = Math.max(dp[i-1][j], dp[i][j- 1]);
20
+ }
21
22
23
+ System.out.println(dp[n][m]);
24
25
+}
26
27
+```
0 commit comments