题解 | #有重复项数字的全排列#
有重复项数字的全排列
http://www.nowcoder.com/practice/a43a2b986ef34843ac4fdd9159b69863
public class Solution {
static ArrayList<ArrayList<Integer>>h=new ArrayList<>();
public ArrayList<ArrayList<Integer>> permuteUnique(int[] num) {
Arrays.sort(num);
ArrayList<Integer>a=new ArrayList<>();
boolean[] now=new boolean[num.length];
dg(num,a,now);
return h;
}
private static void dg(int[] num, ArrayList<Integer> a,boolean[] now) {
if (a.size()==num.length){
if (h.contains(a)) {
return;
}else {
h.add(new ArrayList<>(a));
return;
}
}
for(int i=0;i<num.length;i++){
if (now[i]==true){
continue;
}
now[i]=true;
a.add(num[i]);
dg(num,a,now);
a.remove(a.size()-1);
now[i]=false;
}
}
}

