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.
1 parent 6798673 commit 27758d2Copy full SHA for 27758d2
Seol-JY/202511/24 BOJ G5 공통 부분 문자열.md
@@ -0,0 +1,29 @@
1
+```java
2
+import java.io.BufferedReader;
3
+import java.io.IOException;
4
+import java.io.InputStreamReader;
5
+
6
+public class Main {
7
+ public static void main(String[] args) throws IOException {
8
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9
+ String s1 = br.readLine();
10
+ String s2 = br.readLine();
11
12
+ int n = s1.length();
13
+ int m = s2.length();
14
+ int[][] dp = new int[n + 1][m + 1];
15
+ int maxLen = 0;
16
17
+ for (int i = 1; i <= n; i++) {
18
+ for (int j = 1; j <= m; j++) {
19
+ if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
20
+ dp[i][j] = dp[i - 1][j - 1] + 1;
21
+ maxLen = Math.max(maxLen, dp[i][j]);
22
+ }
23
24
25
26
+ System.out.println(maxLen);
27
28
+}
29
+```
0 commit comments