We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4bddef0 commit 83dea75Copy full SHA for 83dea75
scripts/algorithms/S/Subsets II/Subsets II.js
@@ -1,29 +1,30 @@
1
+// Runtime: 125 ms (Top 19.54%) | Memory: 44.7 MB (Top 48.96%)
2
var subsetsWithDup = function(nums) {
3
let result = [];
4
//sort the nums to avoid duplicates;
5
nums.sort((a,b) => a -b);
6
result.push([]);
-
7
+
8
let startIdx = 0;
9
let endIdx = 0;
10
11
for(let i =0; i<nums.length; i++){
12
let current = nums[i];
13
startIdx = 0;
14
15
//check for duplicates and get the idx of last subset
16
if(i> 0 && nums[i] === nums[i-1]){
17
startIdx = endIdx +1;
18
}
19
endIdx = result.length - 1;
20
21
for(let j = startIdx; j< endIdx+1; j++){
22
let set1 = result[j].slice(0);
23
set1.push(current);
24
result.push(set1);
25
26
27
28
return result;
29
-};
30
+};
0 commit comments