Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: nums = [1,2,3]
Output:
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
class Solution {
public:
void combinedfs(int start, vector<int>& nums,vector<int> &vec,vector<vector<int>> &result)
{
result.push_back(vec);
for(int i=start;i<nums.size();i++)
{
vec.push_back(nums[i]);
combinedfs(i+1,nums,vec,result);
vec.pop_back();
}
}
vector<vector<int>> subsets(vector<int>& nums) {
vector<int> vec;
vector<vector<int>> result;
sort(nums.begin(),nums.end());
combinedfs(0,nums,vec,result);
return result;
}
};