mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
Merge pull request #213 from LiangDazhu/patch-13
添加 0763.划分字母区间 python版本
This commit is contained in:
@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user