Subsets

来源:互联网 发布:淘宝店铺会员制度 编辑:程序博客网 时间:2024/05/21 15:40

Given a set of distinct integers, S, return all possible subsets.

Note:

  • Elements in a subset must be in non-descending order.
  • The solution set must not contain duplicate subsets.


class Solution {public:    void foo(vector<int> &S, int beginIdx, vector<int> &curVtr, vector<vector<int> > &retVtr)    {        retVtr.push_back(curVtr);                for (int i=beginIdx; i<S.size(); i++)        {            curVtr.push_back(S[i]);            foo(S, i+1, curVtr, retVtr);            curVtr.pop_back();        }    }    vector<vector<int> > subsets(vector<int> &S) {                vector<vector<int> > retVtr;        vector<int> curVtr;                sort(S.begin(), S.end());                int len = S.size();                foo(S, 0, curVtr, retVtr);                return retVtr;    }};


0 0
原创粉丝点击