-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path90.cpp
More file actions
executable file
·45 lines (45 loc) · 1.23 KB
/
90.cpp
File metadata and controls
executable file
·45 lines (45 loc) · 1.23 KB
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
class Solution {
public:
vector<int> tmp;
vector<vector<int>> answer;
vector<int> input_nums;
int bucket[100000];
void dfs(int index){
//reach the end
if (index == input_nums.size()){
answer.push_back(tmp);
return;
}
bool last_round_flag = false;
int tmpindex =index;
if (index > 0 && input_nums[index-1] == input_nums[index]){
if (bucket[index-1] == 0){
dfs(index+1);
}else{
bucket[index] = 1;
tmp.push_back(input_nums[index]);
dfs(index+1);
tmp.pop_back();
bucket[index] = 0;
// Not Contain This Element
dfs(index+1);
}
}
else{
bucket[index] = 1;
tmp.push_back(input_nums[index]);
dfs(index+1);
tmp.pop_back();
bucket[index] = 0;
// Not Contain This Element
dfs(index+1);
}
}
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
sort(nums.begin(),nums.end());
memset(bucket,0,sizeof(bucket));
input_nums = nums;
dfs(0);
return answer;
}
};