题解 | #集合的所有子集(一)#
集合的所有子集(一)
http://www.nowcoder.com/practice/c333d551eb6243e0b4d92e37a06fbfc9
粗暴的dfs运用
class Solution {
public:
vector<vector<int> > ans;
void back(const vector<int> &s,int pos,vector<int> &temp){
ans.push_back(temp);
for(int i = pos;i < s.size();++i){
temp.push_back(s[i]);
back(s,i + 1,temp);
temp.pop_back();
}
}
vector<vector<int> > subsets(vector<int> &S) {
vector<int> temp;
back(S,0,temp);
return ans;
}
};