File tree 1 file changed +8
-7
lines changed
scripts/algorithms/S/Subsets II
1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 25 ms (Top 5.31%) | Memory: 8.3 MB (Top 35.96%)
1
2
class Solution {
2
3
public:
3
- vector<vector<int >> ans;
4
+ vector<vector<int >> ans;
4
5
void recur (vector<int >& nums, int i, vector<int > vec){
5
6
if (i > nums.size ()){
6
7
return ;
7
8
}
8
9
for (int j = i; j < nums.size (); j++){
9
10
vec.push_back (nums[j]);
10
-
11
+
11
12
vector<int > temp = vec;
12
13
sort (vec.begin (), vec.end ());
13
-
14
+
14
15
if (find (ans.begin (), ans.end (), vec) == ans.end ()){
15
16
ans.push_back (vec);
16
17
}
17
-
18
+
18
19
recur (nums, j + 1 , vec);
19
-
20
+
20
21
// can't just pop_back any need to pop_back the one we added
21
22
vec = temp;
22
23
vec.pop_back ();
23
24
}
24
25
}
25
-
26
+
26
27
vector<vector<int >> subsetsWithDup (vector<int >& nums) {
27
28
vector<int > vec;
28
29
ans.push_back (vec);
29
30
recur (nums, 0 , vec);
30
-
31
+
31
32
return ans;
32
33
}
33
34
};
You can’t perform that action at this time.
0 commit comments