package com.cn.interviewdemo.day01;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
public class TestArrange{
public static void main(String[] args) {
String str = "123";
List list = toCollection(str);
listAll(list, "", 3);
}
public static List toCollection(String str){
List list = new ArrayList();
for(int i = 0;i < str.length();i++){
list.add(str.charAt(i));
}
return list;
}
public static void listAll(List candidate,String prefix,int length){
if(prefix.length() == length)
System.out.print(prefix+" ");
for(int i = 0;i < candidate.size();i++){
List tem = new LinkedList(candidate);
listAll(tem, prefix+tem.remove(i), length);
}
}
}
有关数学中的全排列的算法实现
最新推荐文章于 2023-05-07 17:20:17 发布