题目
题源

代码
class Solution {
public List<Integer> partitionLabels(String s) {
int[] lastIndexsOfChar = new int[26];
for (int i = 0; i < s.length(); i++) {
lastIndexsOfChar[s.charAt(i) - 'a'] = i;
}
List<Integer> partitions = new ArrayList<>();
int firstIndex = 0;
while (firstIndex < s.length()) {
int lastIndex = firstIndex;
for (int i = firstIndex; i < s.length() && i <= lastIndex; i++) {
int index = lastIndexsOfChar[s.charAt(i) - 'a'];
if (index > lastIndex) {
lastIndex = index;
}
}
partitions.add(lastIndex - firstIndex + 1);
firstIndex = lastIndex + 1;
}
return partitions;
}
}