Given a set of distinct integers, nums, return all possible subsets.
Note: The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,3]
, a solution is:
[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
class Solution {
public:
void subset(vector<vector<int>>& result,vector<int>&path,int step,vector<int>&nums)
{
if(nums.size() == step)
{
result.push_back(path);
return;
}
subset(result,path,step+1,nums);
path.push_back(nums[step]);
subset(result,path,step+1,nums);
path.pop_back();
}
vector<vector<int>> subsets(vector<int>& nums) {
vector<vector<int>> result;
if(nums.size() == 0)
{
return result;
}
vector<int> path;
subset(result,path,0,nums);
return result;
}
};