public List<List<Integer>> permuteUnique(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
Arrays.sort(nums);
backtrack(res, new ArrayList<>(),nums,new boolean[nums.length]);
return res;
}
public void backtrack(List<List<Integer>> res, ArrayList<Integer> tempList, int[] nums,boolean[] used){
if(tempList.size()==nums.length){
res.add(new ArrayList<>(tempList));
}
for(int i=0;i<nums.length;i++){
if(used[i]||i>0&&nums[i]==nums[i-1]&&!used[i-1]) continue;
used[i]=true;
tempList.add(nums[i]);
backtrack(res,tempList,nums,used);
used[i] = false;
tempList.remove(tempList.size()-1);
}
}