/*
* 获取两个字符串中相同的最大子串
* 思路:
* A:将短的字符串进行长度递减的子串打印;
* B:将短的子串与长串进行比较,是否包含;
* C:如果包含,则找到了
* */
public class GetMaxSubString {
public static void main(String[] args) {
String s1 = "wechinajavaweb";
String s2 = "jawevahewechinallowowelord";
String s = getMaxSubString(s2, s1);
sop("包含的最大字符 : "+s);
}
public static void sop(Object obj) {
System.out.println(obj);
}
public static String getMaxSubString(String s1,String s2){
for (int i = 0; i <s2.length(); i++) {
for(int y =0,z=s2.length()-i;z!=s2.length()+1;y++,z++){
String temp = s2.substring(y,z);
sop(temp);
if(s1.contains(temp))
return temp;
}
}
return "";
}
}
|
|