class Solution {
public List<Integer> partitionLabels(String s) {
int[] count = new int[26];
for (int i = 0; i < s.length(); i++) {
count[s.charAt(i) - 'a'] = i;
}
List<Integer> res = new ArrayList<>();
int left = 0;
int right = 0;
for (int i = 0; i < s.length(); i++) {
right = Math.max(right, count[s.charAt(i) - 'a']);
if (i == right) {
res.add(right - left + 1);
left = i + 1;
}
}
return res;
}
}