-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (27 loc) · 715 Bytes
/
index.js
File metadata and controls
30 lines (27 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @param {number[]} nums
* @return {number[][]}
*/
var permute = function(nums) {
const result = [];
permuteHelp(nums, []);
return result;
function permuteHelp(arrs, permute_arr) {
if (arrs.length === 0) {
result.push(permute_arr);
return;
}
for (let i = 0; i < arrs.length; i++) {
permute_arr.push(arrs[i]);
permuteHelp(arrs.filter((item) => permute_arr.indexOf(item) === -1), [...permute_arr]);
permute_arr.pop();
}
}
};
console.log(permute([1,2,3]))
module.exports = {
id:'46',
title:'Permutations',
url:'https://leetcode.com/problems/permutations/',
difficulty:'medium',
};