给定两个字符串s1,s2,写函数输出s1和s2的最长公共子串
var subS="";
var subLen=0;
var s1="dlajadoueowfljlj0000123456ldjfl1111111111111alfj";
var s2="lfjaldjuaoewnn0000123456jdfjsiol1111111111111alf";
for(let i=0;i<s1.length;i++){
for(let j=1;j<=s1.length-i;j++){
if(s2.indexOf(s1.substr(i,j))<0) {
if(j-1>subLen){
subLen=j-1;
substr=s1.substr(i,j-1);
}
break;
}
}
}
console.log(substr,subLen);//l1111111111111alf 17
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634529.html