递归求各种组合情况

来源:互联网 发布:i3-2350m编程好用吗 编辑:程序博客网 时间:2024/05/22 10:43
public class recursion {    public static void main(String[] arg){        String[] strings = new String[]{"1","2","3"};        listAll(Arrays.asList(strings),"");    }    public static void listAll(List candidate,String prefix){        System.out.println(prefix+" ");        for(int i=0;i<candidate.size();i++){            List temp = new LinkedList(candidate);            listAll(temp,prefix+temp.remove(i));        }    } }
结果:
1 12 123 13 132 2 21 213 23 231 3 31 312 32 321 
原创粉丝点击