From 494a24fc5d4eaf0a3388c30930fb7e82438f6bb3 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Sun, 16 May 2021 09:50:25 +0800 Subject: [PATCH] =?UTF-8?q?0046.=E5=85=A8=E6=8E=92=E5=88=97.md=20Javascrip?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0046.全排列.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/problems/0046.全排列.md b/problems/0046.全排列.md index 05d86785..c9a52287 100644 --- a/problems/0046.全排列.md +++ b/problems/0046.全排列.md @@ -188,6 +188,33 @@ Python: Go: +Javascript: +```Javascript + +var permute = function(nums) { + let result = [] + let path = [] + function backtracing(used) { + if(path.length === nums.length) { + result.push(path.slice(0)) + return + } + for(let i = 0; i < nums.length; i++) { + if(used[nums[i]]) { + continue + } + used[nums[i]] = true + path.push(nums[i]) + backtracing(used) + path.pop() + used[nums[i]] = false + } + } + backtracing([]) + return result +}; + +```