forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0090.cpp
31 lines (30 loc) · 866 Bytes
/
0090.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
vector<vector<int>> subsetsWithDup(vector<int>& nums)
{
sort(nums.begin(), nums.end());
vector<vector<int>> result;
vector<int> path;
_subsetsWithDup(nums, 0, path, result);
return result;
}
private:
void _subsetsWithDup(vector<int>& nums, int index, vector<int>& path, vector<vector<int>>& result)
{
result.push_back(path);
for (int i = index; i < nums.size(); ++i)
{
if (index < i and nums[i] == nums[i - 1]) continue;
path.push_back(nums[i]);
_subsetsWithDup(nums, i + 1, path, result);
path.pop_back();
}
}
};