来个莫名AC的(bushi)
import java.util.*;
public class Solution {
ArrayList<ArrayList<Integer>> res = new ArrayList<>();
ArrayList<Integer> path = new ArrayList<>();
public ArrayList<ArrayList<Integer>> subsetsWithDup(int[] num) {
Arrays.sort(num);
dfs(num,0);
return res;
}
public void dfs(int[] num , int index){
if(!res.contains(path)){
res.add(new ArrayList<>(path));
}
for(int i = index ; i < num.length ; i++){
path.add(num[i]);
dfs(num,i+1);
path.remove(path.size()-1);
}
}
}
京公网安备 11010502036488号