题解 | #集合的所有子集(一)#
集合的所有子集(一)
https://www.nowcoder.com/practice/c333d551eb6243e0b4d92e37a06fbfc9
#include <vector>
class Solution {
public:
void dfs(vector<vector<int>> & ans, vector<int> &temp, vector<int> S, int n, int start){
ans.push_back(temp);
for(int i = start; i < n; i++){
temp.push_back(S[i]);
dfs(ans, temp, S, n, i + 1);
temp.pop_back();
}
}
vector<vector<int> > subsets(vector<int>& S) {
// write code here
vector<int> temp;
vector<vector<int>> ans;
int n = S.size();
dfs(ans, temp, S, n, 0);
return ans;
}
};
基恩士成长空间 453人发布
