From 5e23ecc64e4e7251225de68d05a372f8bfbcb47a Mon Sep 17 00:00:00 2001 From: LiangDazhu <42199191+LiangDazhu@users.noreply.github.com> Date: Thu, 20 May 2021 23:07:09 +0800 Subject: [PATCH] =?UTF-8?q?Update=200763.=E5=88=92=E5=88=86=E5=AD=97?= =?UTF-8?q?=E6=AF=8D=E5=8C=BA=E9=97=B4.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added python version code --- problems/0763.划分字母区间.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/problems/0763.划分字母区间.md b/problems/0763.划分字母区间.md index c1474280..a6ca0ea0 100644 --- a/problems/0763.划分字母区间.md +++ b/problems/0763.划分字母区间.md @@ -108,7 +108,23 @@ class Solution { ``` Python: +```python +class Solution: + def partitionLabels(self, s: str) -> List[int]: + hash = [0] * 26 + for i in range(len(s)): + hash[ord(s[i]) - ord('a')] = i + result = [] + left = 0 + right = 0 + for i in range(len(s)): + right = max(right, hash[ord(s[i]) - ord('a')]) + if i == right: + result.append(right - left + 1) + left = i + 1 + return result +``` Go: