急:用java或者js/jquery对字符串如:ABC输出它的所有组合
比如有ABC字符串,需要以数组的形式输出【ABC,AB,AC,BC,A,B,C】或以字符串形式:“ABC,AB,AC,BC,A,B,C”这样的组合....
比如有ABC字符串,需要以数组的形式输出【ABC,AB,AC,BC,A,B,C】或以字符串形式:“ABC,AB,AC,BC,A,B,C”这样的组合.
展开
展开全部
<!DOCTYPE HTML>
<html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script>
function recursionSub ( list, count, array, ind,
start, indexs )
{
start++;
if (start > count - 1)
{
return;
}
if (start == 0)
{
indexs = new Array(array.length);
}
for ( indexs[start] = ind; indexs[start] < array.length; indexs[start]++ )
{
recursionSub (list, count, array, indexs[start] + 1, start, indexs);
if (start == count - 1)
{
temp = new Array(count);
for ( var i = count - 1; i >= 0; i-- )
{
temp[start - i] = array[indexs[start - i]];
}
var flag = true;
L: for ( var i = 0; i < temp.length; i++ )
{
for ( var j = i + 1; j < temp.length; j++ )
{
if (temp[i] == temp[j])
{
flag = false;
break L;
}
}
}
if (flag)
{
list.push (temp);
}
}
}
}
var str = "ABC";
var arr = str.split("");
var list = [];
for(var i=0;i<arr.length;i++){
recursionSub (list, i+1, arr, 0, -1);
console.info(list);
list = [];
}
// 回答完毕,采纳即可。
</script>
</head>
<body>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询