We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 85de096 commit e335150Copy full SHA for e335150
PermutationsII/PermutationsII.cpp
@@ -29,3 +29,33 @@ class Solution {
29
return true;
30
}
31
};
32
+
33
+// recursive solution
34
+class Solution {
35
+public:
36
+ void helper(vector<vector<int>>& result, vector<int>& num, int x) {
37
+ if (x == num.size()) {
38
+ result.push_back(num);
39
+ return;
40
+ }
41
+ helper(result, num, x + 1);
42
+ map<int, bool> hash;
43
+ hash[num[x]] = true;
44
+ for (int i = x + 1; i < num.size(); i++) {
45
+ if (hash[num[i]]) {
46
+ continue;
47
48
+ hash[num[i]] = true;
49
+ swap(num[x], num[i]);
50
51
52
53
54
55
+ vector<vector<int> > permuteUnique(vector<int> &num) {
56
+ sort(num.begin(), num.end());
57
+ vector<vector<int>> result;
58
+ helper(result, num, 0);
59
+ return move(result);
60
61
+};
0 commit comments