publicList<List<Integer>>permute(int[] nums) {List<List<Integer>> res =newArrayList<>();res.add(newArrayList<Integer>());if (nums ==null||nums.length==0) {return res; }for (int i =0; i <nums.length; i++) {List<List<Integer>> oneRound =newArrayList<>();for (List<Integer> cur : res) {// because you need to insert from front to end so + 1for (int j =0; j <cur.size() +1; j++) {cur.add(j, nums[i]);List<Integer> tmp =newArrayList<Integer>(cur);oneRound.add(tmp);cur.remove(j); } } res = oneRound; }return res;}