解题思路:
class Solution {
public List<Integer> partitionLabels(String s) {
int[] last = new int[26];
int len = s.length();
for (int i = 0; i < len; i++) {
last[s.charAt(i) - 'a'] = i;//记录字母最远的下标
}
List<Integer> partition = new ArrayList<>();
int start = 0, end = 0;
for (int i = 0; i < len; i++) {
end = Math.max(end, last[s.charAt(i) - 'a']);
if (i == end) {
partition.add(end - start + 1);
start = end + 1;
}
}
return partition;
}
}