import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param num int整型一维数组
* @return int整型ArrayList<ArrayList<>>
*/
public void recursion(ArrayList<ArrayList<Integer>> res,ArrayList<Integer> temp,int[] num,boolean[] vis){
if(temp.size() == num.length){
res.add(new ArrayList<Integer>(temp));
}
for(int i = 0; i < num.length; i++){
if(vis[i])
continue;
if(i > 0 && num[i-1] == num[i] && !vis[i-1])
continue;
vis[i] = true;
temp.add(num[i]);
recursion(res,temp,num,vis);
vis[i] = false;
temp.remove(temp.size()-1);
}
}
public ArrayList<ArrayList<Integer>> permuteUnique (int[] num) {
// write code here
ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> temp = new ArrayList<Integer>();
Arrays.sort(num);
boolean[] vis = new boolean[num.length];
Arrays.fill(vis,false);
recursion(res,temp,num,vis);
return res;
}
}