官解
vector<vector<int>> v;
vector<int> t;
void dfs(vector<int> &nums,int i){
if(i == nums.size()){
v.push_back(t); return ;
}
t.push_back(nums[i]);
dfs(nums,i + 1);
t.pop_back();
dfs(nums,i + 1);
}
vector<vector<int>> subsets(vector<int>& nums) {
dfs(nums,0);
return v;
}
vector<int> t;
vector<vector<int>> v;
vector<vector<int>> subsets(vector<int>& nums) {
int size = nums.size();
for(int mask = 0; mask < (1 << size); mask++){
t.clear();
for(int i = 0; i < size; i++){
if(mask & (1 << i)) t.push_back(nums[i]);
}
v.push_back(t);
}
return v;
}
vector<int> t;
vector<vector<int>> v;
void dfs(vector<int> nums,int n){
v.push_back(t);
for(int i = n; i < nums.size(); i++){
t.push_back(nums[i]);
dfs(nums,i+1);
t.pop_back();
}
}
vector<vector<int>> subsets(vector<int>& nums) {
dfs(nums,0);
return v;
}