import java.util.*;
public class Solution {
ArrayList<ArrayList<Integer>> ret;
ArrayList<Integer> path;
boolean[] check;
public ArrayList<ArrayList<Integer>> permuteUnique (int[] num) {
ret = new ArrayList<ArrayList<Integer>>();
Arrays.sort(num);
path = new ArrayList<Integer>();
check = new boolean[num.length];
dfc(num);
return ret;
}
public void dfc(int[]num){
//终止条件
if(num.length==path.size()){
//没有该全排列时再加入
if(!ret.contains(new ArrayList<>(path))){
ret.add(new ArrayList<>(path));
}
return;
}
for(int i=0;i<num.length;i++){
//当没有加入过该节点时
if(check[i]==false){
//加入
path.add(num[i]);
check[i] = true;
//进入下一层加入
dfc(num);
//到最后回溯
check[i] = false;
path.remove(path.size()-1);
}
}
}
}