class Solution {
public:
vector<int> partitionLabels(string s) {
int last[26];
int len = s.size();
for (int i = 0; i < len; i++) last[s[i] - 'a'] = i;
vector<int> partition;
int start = 0, end = 0;
for (int i = 0; i < len; i++) {
end = max(end, last[s[i] - 'a']);
if (i == end) {
partition.emplace_back(end - start + 1);
start = end = i + 1;
}
}
return partition;
}
};