Merge pull request #213 from LiangDazhu/patch-13

添加 0763.划分字母区间 python版本
This commit is contained in:
Carl Sun
2021-05-21 15:38:22 +08:00
committed by GitHub

View File

@ -108,7 +108,23 @@ class Solution {
``` ```
Python 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 Go