From 2ed2d8bf13e823df335492d806c6d069fa32b9ff Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Wed, 16 Jun 2021 08:10:13 +0800 Subject: [PATCH] =?UTF-8?q?0763.=E5=88=92=E5=88=86=E5=AD=97=E6=AF=8D?= =?UTF-8?q?=E5=8C=BA=E9=97=B4.md=20Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0763.划分字母区间.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md index bcdd71dc..1e2fcc03 100644 --- a/problems/0763.划分字母区间.md +++ b/problems/0763.划分字母区间.md @@ -128,7 +128,26 @@ class Solution: Go: - +Javascript: +```Javascript +var partitionLabels = function(s) { + let hash = {} + for(let i = 0; i < s.length; i++) { + hash[s[i]] = i + } + let result = [] + let left = 0 + let right = 0 + for(let i = 0; i < s.length; i++) { + right = Math.max(right, hash[s[i]]) + if(right === i) { + result.push(right - left + 1) + left = i + 1 + } + } + return result +}; +``` -----------------------