var findSubsequences = function(nums) {
let result = []
let path = []
let fn = (index) => {
if(path.length > 1 ){
result.push([...path])
}
let map = {}
for(let i=index;i<nums.length;i++){
if(i > index && map[nums[i]]) continue
if(path.length > 0){
let node = path[path.length - 1]
if(nums[i] >= node){
path.push(nums[i])
}else{
continue
}
}else{
path.push(nums[i])
}
map[nums[i]] = true
fn(i+1)
path.pop()
}
}
fn(0)
return result
};
var permute = function(nums) {
let result = []
let path = []
let map = {}
let fn = () =>{
if(path.length === nums.length){
result.push([...path])
return
}
for(let i=0;i<nums.length;i++){
let num = nums[i]
if(map[num]) continue
map[num] = true
path.push(num)
fn()
path.pop()
map[num] =false
}
}
fn()
return result
};
nums.sort((a, b) => {
return a - b
})
let result = []
let path = []
let fn = (used)=>{
if(path.length === nums.length){
result.push([...path])
return
}
for(let i=0;i<nums.length;i++){
if(i>0 && nums[i] === nums[i-1] && !used[i-1]){
continue
}
if(!used[i]){
path.push(nums[i])
used[i] = true
fn(used)
used[i] =false
path.pop()
}
}
}
fn([])
return result
};
var permuteUnique = function(nums) {
nums.sort((a, b) => {
return a - b
})
let result = []
let path = []
let fn = (used)=>{
if(path.length === nums.length){
result.push([...path])
return
}
for(let i=0;i<nums.length;i++){
if(i>0 && nums[i] === nums[i-1] && !used[i-1]){
continue
}
if(!used[i]){
path.push(nums[i])
used[i] = true
fn(used)
used[i] =false
path.pop()
}
}
}
fn([])
return result
};
```var permuteUnique = function(nums) {
nums.sort((a, b) => {
return a - b
})
let result = []
let path = []
let fn = (used)=>{
if(path.length === nums.length){
result.push([...path])
return
}
for(let i=0;i<nums.length;i++){
if(i>0 && nums[i] === nums[i-1] && !used[i-1]){
continue
}
if(!used[i]){
path.push(nums[i])
used[i] = true
fn(used)
used[i] =false
path.pop()
}
}
}
fn([])
return result
};