Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit d6adab8

Browse files
Create 47_Permutations2.js
1 parent af0b0bb commit d6adab8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var permuteUnique = function(nums) {
2+
3+
let permutations = []
4+
5+
const findUniquePerm = function(visited = new Set(), currPerm = []) {
6+
if (currPerm.length === nums.length){
7+
permutations.push(currPerm)
8+
return
9+
}
10+
let uniqueVal = new Set()
11+
12+
for (let i = 0; i < nums.length; i++) {
13+
if (!uniqueVal.has(nums[i]) && !visited.has(i)) {
14+
uniqueVal.add(nums[i])
15+
findUniquePerm(new Set([...visited, i]), [...currPerm, nums[i]])
16+
}
17+
}
18+
}
19+
20+
findUniquePerm()
21+
22+
return permutations
23+
};

0 commit comments

Comments
 (0)