Leetcode 763. Partition Labels
Partition Labels - LeetCode
A string S of lowercase English letters is given. We want to partition this string into as many parts as possible so…
S of lowercase English letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing the size of these parts.
Input: S = "ababcbacadefegdehijhklij"
The partition is "ababcbaca", "defegde", "hijhklij".
This is a partition so that each letter appears in at most one part.
A partition like "ababcbacadefegde", "hijhklij" is incorrect, because it splits S into less parts.
Swill have length in range
Swill consist of lowercase English letters (
- need to understand the question, partition the string at most possible
- update all alphbet last appearance, a substring need to include all its index
- Therefore, create two pointers, first one note the begining, another one note the last appearance index. Once we scan through the string, if there is a bigger index pop out, will need to update the last index.
- Be careful for the add need to be “start + last -1”; and start = last+1;