美文网首页
subsets-ii

subsets-ii

作者: DaiMorph | 来源:发表于2019-06-27 00:54 被阅读0次
    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;
    };
    

    相关文章

      网友评论

          本文标题:subsets-ii

          本文链接:https://www.haomeiwen.com/subject/hcmkcctx.html