一:题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ad6e1e5177a600fca0d9a6e91898c3c1.png)
二:上码
class Solution {
private List<List<Integer>> ans = new ArrayList<>();
private List<Integer> path = new ArrayList<>();
private boolean[] used;
public void getAns(int[] nums,boolean[] used) {
if (path.size() == nums.length) {
ans.add(new ArrayList<>(path));
}
for (int i = 0; i < nums.length; i++) {
if (i > 0 && nums[i] == nums[i-1] && used[i-1] == false) continue;
if (used[i] == false) {
used[i] = true;
path.add(nums[i]);
getAns(nums,used);
path.remove(path.size()-1);
used[i] = false;
}
}
}
public List<List<Integer>> permuteUnique(int[] nums) {
Arrays.sort(nums);
used = new boolean[nums.length];
getAns(nums,used);
return ans;
}
}