-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathp090.cpp
54 lines (52 loc) · 1.38 KB
/
p090.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Solution {
public:
unordered_map<int, int> dict;
vector<vector<int>> result;
void f(int *cur, int cursize, unordered_map<int, int>::iterator iter)
{
if (iter == dict.end())
{
vector<int> addv(cursize);
for (int i = 0; i < cursize; i++)
{
addv[i] = cur[i];
}
result.push_back(addv);
return;
}
int i;
int val = iter->first;
unordered_map<int, int>::iterator jter = iter;
jter++;
f(cur, cursize, jter);
for (i = 0; i < iter->second; i++)
{
cur[cursize++] = iter->first;
f(cur, cursize, jter);
}
cursize -= iter->second;
}
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
int i;
int size = nums.size();
int val;
unordered_map<int, int>::iterator iter;
for (i = 0; i < size; i++)
{
val = nums[i];
iter = dict.find(val);
if (iter == dict.end())
{
dict.insert(pair<int, int>(val, 1));
}
else
{
iter->second++;
}
}
int *tmp = new int[size];
iter = dict.begin();
f(tmp, 0, iter);
return result;
}
};