class Solution {
public:
vector<vector<int> > subsets(vector<int> &s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<vector<int> > vv;
vector<int> v;
sort(s.begin(),s.end());
helper(vv,v,s,0);
return vv;
}
void helper(vector<vector<int> >& vv,vector<int>& v,vector<int>& s,int index){
vv.push_back(v);
if(index==s.size())
return;
for(int i=index;i<s.size();++i){
v.push_back(s[i]);
helper(vv,v,s,i+1);
v.pop_back();
}
}
};
Leetcode: Subsets (Recursive)
最新推荐文章于 2022-01-25 17:40:57 发布