subset
code
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
int n = nums.size();
vector<vector<int>> res;
if(n == 0)
{
return res;
}
vector<int> cur;
dfs(res, nums, cur, 0);
return res;
}
void dfs(vector<vector<int>>& res, vector<int>& nums, vector<int>& cur, int pos)
{
if(pos > nums.size())
{
return ;
}
res.push_back(cur);
for(int i = pos; i<nums.size(); i++)
{
cur.push_back(nums[i]);
dfs(res, nums, cur, i+1);
cur.pop_back();
}
}
};