给定一个不含重复数字的数组 nums ,返回其 所有可能的全排列 。你可以 按任意顺序 返回答案。
123456789101112131415
var permute = function (nums) { let curItems = [[]] for (const val of nums) { const nextItems = [] for (const items of curItems) { for (let j = 0; j <= items.length; ++j) { const curVals = [...items] curVals.splice(j, 0, val) nextItems.push(curVals) } } curItems = nextItems } return curItems}