/**
* @param {number[]} nums
* @return {number[][]}
47. 全排列 II
*/
var permuteUnique = function(nums) {
const dfs = (curr, store, arr, len) => { // [] [1,1,2] [] 3
if (curr.length === len) { // [1,2,3] [] [] 3
arr.push([...curr]);
return;
}
// [1] [1,2] [] 3
// [1, 1] [2] [] 3
// 遍历数组
for(let i = 0; i < store.length; i++) {
if (i>0 && store[i] === store[i-1]) {
continue;
}
let select = store[i];
dfs(
curr.concat(select),
store.slice(0, i).concat(store.slice(i+1)),
arr,
len
)
}
}
let ans = [];
nums.sort((a,b) => a -b);
dfs([], nums, ans, nums.length);
return ans;
};
let s = new Set();
undefined
s.add([1,2,3]);
Set(1) {Array(3)}
s.add([1,2,3]);
Set(2) {Array(3), Array(3)}
[[Entries]]
0: Array(3)
value: (3) [1, 2, 3]
1: Array(3)
value: (3) [1, 2, 3]
size: 2
[[Prototype]]: Set
s.add(1,2,3);
Set(3) {Array(3), Array(3), 1}
[[Entries]]
0: Array(3)
1: Array(3)
2: 1
value: 1
size: 3
[[Prototype]]: Set
s.add('123');
Set(4) {Array(3), Array(3), 1, '123'}
[[Entries]]
0: Array(3)
1: Array(3)
2: 1
3: "123"
value: "123"
size: 4
[[Prototype]]: Set
s.add('123');
Set(4) {Array(3), Array(3), 1, '123'}
[[Entries]]
0: Array(3)
1: Array(3)
2: 1
3: "123"
value: "123"
size: 4
[[Prototype]]: Set