From 0131465339d570fb8c47ddea3eb8f9a7d6cbf577 Mon Sep 17 00:00:00 2001 From: 5Reason Date: Tue, 6 Dec 2022 12:03:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20131.=E5=88=86=E5=89=B2?= =?UTF-8?q?=E5=9B=9E=E6=96=87=20=E4=B8=B2=20js=E4=BB=A3=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=90=8D,=E5=92=8C=E6=95=99=E7=A8=8B?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4=E9=81=BF=E5=85=8D=E6=B7=B7?= =?UTF-8?q?=E6=B7=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0131.分割回文串.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/problems/0131.分割回文串.md b/problems/0131.分割回文串.md index 3a3c2d73..8e180ec8 100644 --- a/problems/0131.分割回文串.md +++ b/problems/0131.分割回文串.md @@ -494,15 +494,15 @@ var partition = function(s) { const res = [], path = [], len = s.length; backtracking(0); return res; - function backtracking(i) { - if(i >= len) { + function backtracking(startIndex) { + if(startIndex >= len) { res.push(Array.from(path)); return; } - for(let j = i; j < len; j++) { - if(!isPalindrome(s, i, j)) continue; - path.push(s.slice(i, j + 1)); - backtracking(j + 1); + for(let i = startIndex; i < len; i++) { + if(!isPalindrome(s, startIndex, i)) continue; + path.push(s.slice(startIndex, i + 1)); + backtracking(i + 1); path.pop(); } }