class Test
{
public static String getMaxSubString(String s1,String s2)
{
String max = "",min = "";
max = (s1.length()>s2.length())?s1:s2;
min = (max==s1)?s2:s1;
sop("max="+max+".....min="+min);
for(int x=0;x<min.length();x++)
{
for(int y=0,z=min.length()-x;z!=min.length()+1;y++,z++)
{
String temp = min.substring(y,z);
if(max.contains(temp));
return temp;
}
}
return "";
}
public static void main(String[] args)
{
String s1 = "abcdef";
String s2 ="ab";
sop(getMaxSubString(s2,s1));
}
希望有大神能给讲明白。for开始....一直到return这块的代码。希望老马能给讲解清晰下。这块代码我很不明白。。:'( |
|