Given a set of distinct integers, nums, return all possible subsets.

Note:

  • Elements in a subset must be in non-descending order.
  • 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],
  []
]

 1 void sub(vector<int> &nums,int s,
 2               vector<int> tmp,vector<vector<int>> &res)
 3     {
 4         int len=nums.size();
 5         for(int i=s;i<len;i++)
 6         {
 7             tmp.push_back(nums[i]);
 8             res.push_back(tmp);
 9             sub(nums,i+1,tmp,res);
10             tmp.pop_back();
11         }
12     }
13 class Solution {
14 public:
15     vector<vector<int>> subsets(vector<int>& nums) {
16        
17         vector<vector<int>> res;
18         res.push_back(vector<int> (0,0));
19         
20         vector<int> tmp;
21         sort(nums.begin(),nums.end());
22         sub(nums,0,tmp,res);
23         return res;
24         
25     }
26 
27 };