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;
}
};