Created
January 22, 2019 04:52
-
-
Save kanrourou/662a8133a275106b58a48ea8885cebd6 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 { | |
public: | |
vector<vector<int>> subsetsWithDup(vector<int>& nums) { | |
vector<vector<int>> res; | |
vector<int> curr; | |
sort(nums.begin(), nums.end()); | |
dfs(nums, 0, curr, res); | |
return res; | |
} | |
private: | |
void dfs(vector<int>& nums, int start, vector<int>& curr, vector<vector<int>>& res) | |
{ | |
res.push_back(curr); | |
for(int i = start; i < nums.size(); ++i) | |
{ | |
if(i > start && nums[i - 1] == nums[i])continue; | |
curr.push_back(nums[i]); | |
dfs(nums, i + 1, curr, res); | |
curr.pop_back(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment