1
var permuteUnique = function (nums) {
2
const answer = [];
3

4
function perm(pos, array) {
5
if (pos >= array.length) {
6
answer.push(array);
7
}
8

9
const setObject = new Set();
10

11
for (let index = pos; index < array.length; index++) {
12
if (setObject.has(array[index])) {
13
continue;
14
}
15
setObject.add(array[index]);
16

17
// swap numbers
18
let temp = array[pos];
19
array[pos] = array[index];
20
array[index] = temp;
21

22
perm(pos + 1, [...array]);
23

24
// undo swapping for next iteration
25
temp = array[index];
26
array[index] = array[pos];
27
array[pos] = temp;
28
}
29
}
30

31
perm(0, nums);
32

33
return answer;
34
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0