/**
* 获取两个字符串中最大相同子串。比如:
* str1 = "abcwerthelloyuiodef“;str2 = "cvhellobnm"
* 提示:将短的那个串进行长度依次递减的子串与较长的串比较。
* @author
* @create 2021-06-08 22:35
*/
public class Test5 {
public static void main(String[] args) {
String s1 = "abcwerthelloyuiodef";
String s2 = "cvhellobnm";
l:for (int i = 0; i < s2.length(); i++) {
for (int j = 0; j - i < 0; j++) {
String s3 = s2.substring(j, s2.length() - i + j);
if(s1.indexOf(s3) != -1){
System.out.println(s3);
break l;
}
}
}
}
}
java字符串常见算法题:获取两个字符串的最大子串
最新推荐文章于 2024-06-21 06:33:17 发布