November 5, 2022 06:19 am GMT
Original Link: https://dev.to/salahelhossiny/partition-labels-5abk
Partition Labels
You are given a string s. We want to partition the string into as many parts as possible so that each letter appears in at most one part.
Note that the partition is done so that after concatenating all the parts in order, the resultant string should be s.
Return a list of integers representing the size of these parts.
class Solution: def partitionLabels(self, S: str) -> List[int]: count = {} res = [] i, length = 0, len(S) for j in range(length): c = S[j] count[c] = j curLen = 0 goal = 0 while i < length: c = S[i] goal = max(goal, count[c]) curLen += 1 if goal == i: res.append(curLen) curLen = 0 i += 1 return res
Original Link: https://dev.to/salahelhossiny/partition-labels-5abk
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To