package myTest;
public class FindMostLargeSubstringDemo {
public static void main(String[] args) {
// TODO 自动生成的方法存根
String s1="asdqwerdfvfrgr";
String s2="wqerasdqmll";
String s=MaxSubstring(s1,s2);
System.out.println("s="+s);
}
String min=null;
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 sub=min.substring(a, b);
if(max.contains(sub))
return sub;
}
}
return null;//没有相同的子串,返回null
}
}
public class FindMostLargeSubstringDemo {
public static void main(String[] args) {
// TODO 自动生成的方法存根
String s1="asdqwerdfvfrgr";
String s2="wqerasdqmll";
String s=MaxSubstring(s1,s2);
System.out.println("s="+s);
}
private static String MaxSubstring(String s1,String s2){
//初始化两个字符串,存s1,s2
String max=null;String min=null;
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 sub=min.substring(a, b);
if(max.contains(sub))
return sub;
}
}
return null;//没有相同的子串,返回null
}
}