Files
js-practice/src/math/permutations.js
2020-04-28 18:36:18 +08:00

16 lines
325 B
JavaScript

/**
* @param {number[]} nums
* @return {number[][]}
*/
export const permute = function (nums) {
const res = []
const backtrack = (path = []) => {
if (path.length === nums.length) res.push(path)
for (const n of nums) {
!path.includes(n) && backtrack(path.concat(n))
}
}
backtrack()
return res
}