全排列:
为了找123, 先固定左边的, 然后找23
/**
* @param {string} s1
* @param {string} s2
* @return {boolean}
*/
var all = function(s2, meature, len) {
let ret = [];
if(s2.length===1) {
ret.push(s2)
} else {
for(let i=0; i<s2.length;i++){
var left = s2[i];
var rest = s2.substring(0,i)+s2.substring(i+1, s2.length)
let list = all(rest, meature, len)
if(list===true) {
return true;
} else {
list.forEach(element => {
var finl = left+element
if(meature.indexOf(finl)>-1 && finl.length==len) {
console.log(9999, meature, finl, meature.indexOf(finl));
return true;
}
ret.push(finl);
});
}
}
}
if(ret===true) return true;
return ret;
}
var number=(num)=>{
let ret = new Array(num).fill(1).reduce((sum, i, index)=>{
sum=sum*(index+1);
return sum;
},1)
console.log(ret);
return ret;
}
var checkInclusion = function(s1, s2) {
if(s1.length>s2.length) return false
ret = all(s1, s2, s1.length);
console.log(ret.length);
if(ret.length<number(s1.length)) {
return true
} else {
return ret.some(i=>{
return s2.indexOf(i)!==-1;
})
}
};
console.log(checkInclusion("trinitrophenylmethylnitramine",
"dinitrophenylhydrazinetrinitrophenylmethylnitramine"));