LC 0763 [M] Partition Labels - ALawliet/algorithms GitHub Wiki
https://www.youtube.com/watch?v=B7m8UmZE-vw&ab_channel=NeetCode
class Solution:
def partitionLabels(self, s: str) -> List[int]:
lastIndex = {} # char -> last index in s
for i, c in enumerate(s):
lastIndex[c] = i
res = []
size, end = 0, 0
for i, c in enumerate(s):
size += 1
if lastIndex[c] > end:
end = lastIndex[c]
end = max(end, lastIndex[c])
if i == end:
res.append(size)
size = 0
return res