public class StringTest4
{
public static void main(String [] args)
{
String str1 = "adcfgeheightkdeffcser";
String str2 = "theightyye";
String result =getMaxString(str1,str2);
System.out.println(result);
}
private static String getMaxString(String str1, String str2)
{
String max =null;
String min = null;
max=(str1.length()>str2.length()?str1:str2);
min=max.equals(str1)?str2:str1;
for (int i = 0; i < min.length(); i++)
{
for(int start=0, end=min.length()-i;end != min.length()+1;start++,end++)
{
String sub = min.substring(start,end);
if(max.contains(sub))
return sub;
}
}
return null;
}
}
————————————————
版权声明:本文为CSDN博主「明明如月学长」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/w605283073/article/details/46572567