90.Subsets II (M)
https://leetcode.com/problems/subsets-ii/
Last updated
https://leetcode.com/problems/subsets-ii/
Last updated
public ArrayList<ArrayList<Integer>> subsetsWithDup(ArrayList<Integer> S){
ArrayList<ArrayList<Integer>> result=new ArrayList<>();
if(S==null || S.size()==0){
return result;
}
ArrayList<Integer> path=new ArrayList<Integer>();
Collections.sort(S);
dfs(S,0,path,result);
return result;
}
public void dfs(ArrayList<Integer> S,int startindex,ArrayList<Integer> path,ArrayList<ArrayList<Integer>> result){
result.add(new ArrayList<Integer>(path));
for(int i=startindex;i<S.size();i++){
if(i!=startindex && S.get(i)==S.get(i-1)){
continue;
}
path.add(S.get(i));
dfs(S,i+1,path,result);
path.remove(path.size()-1);
}
}