subsets-ii

2019-06-27  本文已影响0人  DaiMorph
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;
};
上一篇下一篇

猜你喜欢

热点阅读