力扣(LeetCode) 链接:https://leetcode.cn/problems/permutations/
解题
/**
* @param {number[]} nums
* @return {number[][]}
*/
var permute = function(nums) {
const res = []
const path = []
let set = new Set()
function bfs(set1){
if(path.length === nums.length){
res.push([...path])
return
}
for(let i = 0; i < nums.length; i++){
if(set.has(nums[i])){
continue
}
set.add(nums[i])
path.push(nums[i])
bfs(set1)
path.pop()
set.delete(nums[i])
}
}
bfs(set)
return res
};
debugger
permute([1,2,3])