/*两个字符串中最大相同的子串
* "qwerabcdtyuiop"
* "xcabcdvbn"
* 思路:
* 1、既然取得是最大子串,先看短的那个字符串是否在字符串中。
* 如果存在,短的那个字符串就是最大子串
* 2、如果不是,那么就将那个子串进行长度递减的方式去子串,去长串中判断是否存在
* 如果存在就已经找到,就不用再找了
*
* */
public class MaxStringFind {
public static void main(String[] args) {
String s1="qwerabcdtyuiop";
String s2="xcabcdvbn";
String s=getMaxSubstring(s1,s2);
System.out.println(s);
}
public static String getMaxSubstring(String s1, String s2) {
String max,min;
max=(s1.length()>s2.length())?s1:s2;
min=(max.equals(s1))?s2:s1;
for (int i = 0; i < min.length(); i++) {
for(int a=0,b=min.length()-i;b!=min.length()+1;a++,b++){
String s=min.substring(a, b);
if(max.contains(s)){
return s;
}
}
}
return null;
}
}