class Solution {
public:
vector<vector<int> > subsetsWithDup(vector<int> &S) {
sort(S.begin(),S.end());
dfs(S,0);
return ans;
}
void dfs(vector<int>&S,int index)
{
ans.push_back(path);
for(int i=index;i<S.size();i++)
{
if(i!=index&&S[i]==S[i-1])continue;
path.push_back(S[i]);
dfs(S,i+1);
path.pop_back();
}
}
private:
vector<vector<int>>ans;
vector<int>path;
};
网友评论