parent
942bd655b6
commit
5e23ecc64e
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue