class Solution {
public:
vector<vector<int>>ans;
vector<int>path;
vector<vector<int> > subsets(vector<int> &S) {
sort(S.begin(),S.end());
if(S.size()==0)return ans;
dfs(S,0);
sort(ans.begin(),ans.end(),comp);
return ans;
}
void dfs(vector<int>S,int index)
{
if(index==S.size())
{
ans.push_back(path);
return;
}
path.push_back(S[index]);
dfs(S,index+1);
path.pop_back();
dfs(S,index+1);
}
static bool comp(vector<int>a,vector<int>b){
if(a.size()<b.size())return true;
else if(a.size()==b.size())return a<b;
else return false;
}
};
网友评论