forked from Ayushsinhahaha/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutations2.cpp
More file actions
36 lines (28 loc) · 759 Bytes
/
Permutations2.cpp
File metadata and controls
36 lines (28 loc) · 759 Bytes
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
class Solution {
public:
vector<int> temp;
vector<vector<int>> ans;
unordered_map<int, int> mp;
vector<vector<int>> permuteUnique(vector<int>& nums) {
int n = nums.size();
for(auto x:nums) mp[x]++;
help(0, n);
return ans;
}
void help(int index, int n){
if(index == n){
ans.push_back(temp);
return;
}
for(auto k:mp){
int key = k.first;
int value = k.second;
if(value == 0) continue;
temp.push_back(key);
mp[key]--;
help(index+1, n);
temp.pop_back();
mp[key]++;
}
}
};