class Solution {
List<List<Integer>> ress = new ArrayList<>();
public List<List<Integer>> permute(int[] nums) {
Arrays.sort(nums);
int[] visited = new int[nums.length];
dfs(nums,new ArrayList<>(),visited);
return ress;
}
public void dfs(int[] nums, List<Integer> res, int[] visited){
if(res.size()==nums.length){
ress.add(new ArrayList<>(res));
return;
}
for(int i=0;i<nums.length;i++){
if(visited[i]==1) continue;
if(i>0 && nums[i]==nums[i-1])continue;
visited[i] = 1;
res.add(nums[i]);
dfs(nums,res,visited);
visited[i] = 0;
res.remove(res.size()-1);
}
}
}