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 8df0bcb + d3cf55e commit 22ac3f0Copy full SHA for 22ac3f0
JHLEE325/202511/25 BOJ G5 공통 부분 문자열.md
@@ -0,0 +1,32 @@
1
+```java
2
+import java.io.*;
3
+import java.util.*;
4
+
5
+public class Main {
6
+ public static void main(String[] args) throws Exception {
7
+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8
9
+ String S1 = br.readLine();
10
+ String S2 = br.readLine();
11
12
+ int n = S1.length();
13
+ int m = S2.length();
14
15
+ int[][] dp = new int[n + 1][m + 1];
16
+ int answer = 0;
17
18
+ for (int i = 1; i <= n; i++) {
19
+ for (int j = 1; j <= m; j++) {
20
+ if (S1.charAt(i - 1) == S2.charAt(j - 1)) {
21
+ dp[i][j] = dp[i - 1][j - 1] + 1;
22
+ answer = Math.max(answer, dp[i][j]);
23
+ } else {
24
+ dp[i][j] = 0;
25
+ }
26
27
28
29
+ System.out.println(answer);
30
31
+}
32
+```
0 commit comments