Update 0763.划分字母区间.md

Added python version code
This commit is contained in:
LiangDazhu
2021-05-20 23:07:09 +08:00
committed by GitHub
parent 942bd655b6
commit 5e23ecc64e

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