import java.util.ArrayList; public class test { static ArrayList<String> list = new ArrayList<>(); public static void main(String[] args) { String[] strs = {"A","B","C","D"}; perm(strs, 0, strs.length); for(String s:list){ System.out.println(s); } list.clear(); } private static void perm(String[] strs,int start,int end){ String s = ""; if(start==end){ for(int i=0;i<strs.length;i++){ s+=strs[i]; } list.add(s); }else{ for(int i=start;i<end;i++){ String str = strs[start]; strs[start] = strs[i]; strs[i] = str; perm(strs,start+1,end); strs[i] = strs[start]; strs[start] = str; } } } }
这是在网上找的代码,但是看不太懂,有哪位大神可以详细讲下思路吗?比如每一步的目的是什么,主要是递归那里真的想不通了
Frank_W毅3947945
相关分类