LC763 - Partition Labels
Problem
Example
Solution
def partitionLabels(self, s: str) -> List[int]:
lastIndex = {}
for i in range(len(s)):
lastIndex[s[i]] = i
res = []
size, end = 0, 0
for i in range(len(s)):
size += 1
if lastIndex[s[i]] > end:
end = lastIndex[s[i]]
if i == end:
res.append(size)
size = 0
return resLast updated