删除字符串任意两个字符剩余字符无重复组合个数,
例:”data”,删除任意两个字符,剩余字符组合个数为5,即”ta”, “aa”, “da”, “at”, “dt”。js实现:
function delStr(str){
var str1 = str.split('');
var temp = str1;
var len = str1.length;
var result = {};
for (var i = 0; i < len; i++) {
temp.splice(i, 1);
var tempLen = temp.length;
var tempStr = temp.join('');
var flag=false;
for (var j = 0; j < tempLen-1; j++) {
tempStr = tempStr.split('');
tempStr.splice(j,1);
tempStr = tempStr.join('');
if (!result[tempStr]) {
result[tempStr] = tempStr;
}
tempStr = temp.join('');
}
temp = str.split('');
}
var num = 0;
var a =[];
for (var k in result) {
num++;
a.push(k);
}
console.log(a);
console.log(num);
}
控制台输出:
["ta", "aa", "da", "at", "dt"]
5