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: vector<vector<int>> subsets(vector<int>& nums) { int length=nums.size(); sort(nums.begin(),nums.end()); vector<vector<int> > result; for(int i=0;i<1<<length;i++) { vector<int> tmp; for(int j=0;j<length;j++) { if(i&1<<j) { tmp.push_back(nums[j]); } } result.push_back(tmp); } return result; } };