Created
February 22, 2018 02:31
-
-
Save sourabh2k15/ec7da852bbea4e3d01865ef4aad2b887 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
private: | |
vector<vector<int>> powerset; | |
vector<int> subset; | |
public: | |
vector<vector<int>> subsets(vector<int>& nums) { | |
backtrack(nums, 0); | |
return powerset; | |
} | |
void backtrack(vector<int>& nums, int start){ | |
if(start == nums.size()) powerset.push_back(subset); | |
else{ | |
subset.push_back(nums[start]); | |
backtrack(nums, start+1); | |
subset.pop_back(); | |
backtrack(nums, start+1); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment