Topic
全排列
输入一个没有重复数字的序列,返回其所有可能的全排列。
function permute(nums) {
function fn(list, tempList, nums) {
if(tempList.length === nums.length) return list.push([...tempList]);
for(let i = 0;i < nums.length;i ++) {
if(tempList.includes(nums[i])) continue;
tempList.push(nums[i]);
fn(list, tempList, nums);
tempList.pop();
}
}
let result = [];
fn(result, [], nums);
return result;
}