题解
class Solution:
def partitionLabels(self
, S
: str) -> List
[int]:
pos
= [[-1,0] for _
in range(26)]
for i
,c
in enumerate(S
):
pos
[ord(c
)-97]=[i
,pos
[ord(c
)-97][1]+1]
left
=-1
maxPos
=-1
result
= []
for i
,c
in enumerate(S
):
if pos
[ord(c
)-97][0]>maxPos
:
maxPos
=pos
[ord(c
)-97][0]
pos
[ord(c
)-97][1]-=1
if pos
[ord(c
)-97][0]==i
and pos
[ord(c
)-97][1]==0 and i
==maxPos
:
print(c
,pos
[ord(c
)-97])
result
.append
(i
-left
)
left
=i
return result
转载请注明原文地址: https://lol.8miu.com/read-31243.html