-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain1.java
More file actions
40 lines (39 loc) · 1.24 KB
/
Copy pathMain1.java
File metadata and controls
40 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main1 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str11 = br.readLine().trim().split(" ");
String str1 = str11[0];
String str2 = str11[1];
System.out.println(Main1.getCommonStrLength(str1,str2));
}
public static String getCommonStrLength(String str1, String str2){
if(str1 == null || str2 == null){
return null;
}
if (str1.equals("") || str2.equals("")){
return null;
}
String max = "";
String min = "";
if(str1.length() < str2.length()){
max = str2;
min = str1;
} else {
max = str1;
min = str2;
}
String current = "";
for(int i = 0; i < min.length(); i++){
for(int begin = 0, end = min.length(); end <= min.length(); begin++,end++){
current = min.substring(begin, end);
if(max.contains(current)){
return current;
}
}
}
return null;
}
}