//求最长相同子特征
function LSC (s1, s2) {
function getNum(n1,n2) {
if(n1<0||n2<0){
return {
s1Arr:[],
s2Arr:[],
num:0
}
}
const is=s1[n1]===s2[n2]?1:0;
if(is){
const l1=getNum(n1-1,n2-1);
l1.s1Arr.push(n1)
l1.s2Arr.push(n2)
l1.num=l1.num+1;
return l1
}else{
const l1=getNum(n1-1,n2-1);
const l2=getNum(n1-1,n2);
const l3=getNum(n1,n2-1);
let lMax=l1;
if(l2.num>l1.num&&l2.num>l3.num){
lMax=l2;
}else if(l3.num>l1.num&&l3.num>l2.num){
lMax=l3;
}
return lMax;
}
}
const obj=getNum(s1.length-1,s2.length-1)
let ctr='';
obj.s1Arr.forEach(function (n) {
ctr+=s1.substr(n,1)
})
return ctr
}
console.log(LSC('121213121,1421','1,21'))