public void helper(int[] nums,int cur,ArrayList<Integer> list,List<List<Integer>> res){
if(list.size()==nums.length){
res.add(new ArrayList<Integer>(list));
return;
}
for(int i=cur;i<nums.length;i++){
for(int j=0;j<=list.size();j++){
list.add(j, nums[i]);
helper(nums,i+1,list, res);
list.remove(j);
}
}
}
//求nums这些数的全排列
public List<List<Integer>> permute(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
helper(nums, 0, new ArrayList<Integer>(), res);
return res;
}
A simple java solution beats lots of codes, 268ms


Also, there are so few test cases and they're so tiny that your solution time almost doesn't matter at all. I just got it accepted in 628 ms despite doing 1000 times as much work:
public List<List<Integer>> permute(int[] nums) { List<List<Integer>> res = null; for (int i=0; i<1000; ++i) { res = new ArrayList<List<Integer>>(); helper(nums, 0, new ArrayList<Integer>(), res); } return res; }
Assuming 252 ms as the baseline, that's (628252)/1000 = 0.376 ms spent by the actual solution, which means 10.376/252 = 99.85% of the time is spent by the judge, not your solution. You have no chance of meaningfully comparing the solution speeds with this. Unless you have a really really awfully slow solution, the time and the time variation are almost purely luck and have nothing to do with your solution.