Java 改进递归算法

Java 改进递归算法,java,performance,list,recursion,Java,Performance,List,Recursion,编辑: 所以我有一个递归代码,它对列表中的数字进行“置乱”,并调用一个方法来检查它们的顺序是否“解决”了下面列出的一个x需求 for(int e=0;e<nums.size();e++){ int v = nums.remove(e); //Takes the number from nums solucion.add(v); //Adds it to the solution if(solve(nums, solution))return true; //Cal

编辑: 所以我有一个递归代码,它对列表中的数字进行“置乱”,并调用一个方法来检查它们的顺序是否“解决”了下面列出的一个x需求

for(int e=0;e<nums.size();e++){
    int v = nums.remove(e); //Takes the number from nums
    solucion.add(v); //Adds it to the solution

    if(solve(nums, solution))return true; //Calls solve recursively

    solution.removeLast(); //Removes the element added to the solution
    nums.add(e,v); //Places the number on its original position 
}
for(int e=0;e