第一段
public String getMaxSameString(String str1, String str2){
String maxStr = (str1.length() >= str2.length()) ? str1 : str2;
String minStr = (str1.length() < str2.length()) ? str1 : str2;
int length = minStr.length();
for (int i = 0; i < length; i++){
for (int x = 0, y = length - i;y <= length;x++, y++){
System.out.println(y);
String substring = minStr.substring(x, y);
if (maxStr.contains(substring)){
return substring;
}
}
}
return null;
}
第二段
public String a(String str1, String str2){
String maxStr = str1.length() >= str2.length() ? str1 : str2;
String minStr = str1.length() < str2.length() ? str1 : str2;
int length = minStr.length();
for (int i = 0; i < length; i++){
String subStr = minStr.substring(i);
if (maxStr.contains(subStr)){
return subStr;
}
}
return null;
}