From cce2cffb7314cf863088579ba2b90dfdc0cfb981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=85=88=E5=AF=8C?= Date: Thu, 13 May 2021 07:48:32 +0800 Subject: [PATCH] =?UTF-8?q?0078.=E5=AD=90=E9=9B=86.md=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0078.子集.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0078.子集.md b/problems/0078.子集.md index 8c68843d..5054246f 100644 --- a/problems/0078.子集.md +++ b/problems/0078.子集.md @@ -184,7 +184,24 @@ Python: Go: +Javascript: +```Javascript +var subsets = function(nums) { + let result = [] + let path = [] + function backtracking(startIndex) { + result.push(path.slice()) + for(let i = startIndex; i < nums.length; i++) { + path.push(nums[i]) + backtracking(i + 1) + path.pop() + } + } + backtracking(0) + return result +}; +``` -----------------------