classSolution {publicList<List<Integer>> permute(int[] nums) {List<List<Integer>> res =newArrayList<>();dfs(nums,0,res);return res; }// depth represents the index in nums which will be swapped with the following integersprivatevoiddfs(int[] nums,int depth,List<List<Integer>> list){if (depth ==nums.length-1) {// to be implementedList<Integer> ans =newArrayList<>();for (int num : nums){ans.add(num); }list.add(ans);return; }for (int i=depth; i<nums.length;i++){swap(nums, depth, i);dfs(nums, depth+1, list);swap(nums, i, depth); } }privatevoidswap(int[] nums,int i,int j){int temp = nums[j]; nums[j]=nums[i]; nums[i]=temp; }}