var permute = function(nums) { var res = [] var path = [] var dfs = (path, nums) => { if (path.length === nums.length) { res.push(path) } for (let num of nums) { if (!path.includes(num)) { path.push(num) dfs(path.slice(), nums) path.pop() } } } dfs(path, nums) return res }