class Solution { void perm(int level, int []nums, List<List<Integer>> list){ if(level==nums.length){ ArrayList<Integer> listSingle = new ArrayList<>(); for(int i=0;i<nums.length;i++){ listSingle.add(nums[i]); } list.add(listSingle); }else{ for(int i=level;i<nums.length;i++){ int temp = nums[i]; nums[i] = nums[level]; nums[level] = temp; perm(level+1,nums,list); temp = nums[i]; nums[i] = nums[level]; nums[level] = temp; } } } public List<List<Integer>> permute(int[] nums) { List<List<Integer>> listAll = new ArrayList<>(); perm(0,nums,listAll); return listAll; } }