From 2b5319631cbae953609c691269668f18e602a632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=85=88=E5=AF=8C?= Date: Sat, 15 May 2021 09:25:24 +0800 Subject: [PATCH] =?UTF-8?q?0491.=E9=80=92=E5=A2=9E=E5=AD=90=E5=BA=8F?= =?UTF-8?q?=E5=88=97.md=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0491.递增子序列.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/problems/0491.递增子序列.md b/problems/0491.递增子序列.md index 5deec0ee..20dcb524 100644 --- a/problems/0491.递增子序列.md +++ b/problems/0491.递增子序列.md @@ -207,6 +207,34 @@ Python: Go: +Javascript: + +```Javascript + +var findSubsequences = function(nums) { + let result = [] + let path = [] + function backtracing(startIndex) { + if(path.length > 1) { + result.push(path.slice()) + } + let uset = [] + for(let i = startIndex; i < nums.length; i++) { + if((path.length > 0 && nums[i] < path[path.length - 1]) || uset[nums[i] + 100]) { + continue + } + uset[nums[i] + 100] = true + path.push(nums[i]) + backtracing(i + 1) + path.pop() + } + } + backtracing(0) + return result +}; + +``` +