/**
* longest common substring
* @param str1 string字符串 the string
* @param str2 string字符串 the string
* @return string字符串
*/
function LCS( str1 , str2 ) {
if(!str1||!str2) return -1;
if(str1.length>str2.length){
[str1,str2] = [str2,str1];
}
let maxlen = 0,res = '';
for(let i=0;i<str1.length;i++){
if(str2.indexOf(str1.slice(i-maxlen, i+1))!==-1){
res = str1.slice(i-maxlen, i+1)
maxlen +=1
}
}
return res || -1
}
module.exports = {
LCS : LCS
};
京公网安备 11010502036488号