fix(0763): 下标取 字母 - 'a' 的值,少点空间

This commit is contained in:
KailokFung
2021-10-18 11:01:38 +08:00
parent 7c8549dcd9
commit cb9a717a7c

View File

@ -88,15 +88,15 @@ Java
class Solution {
public List<Integer> partitionLabels(String S) {
List<Integer> list = new LinkedList<>();
int[] edge = new int[123];
int[] edge = new int[26];
char[] chars = S.toCharArray();
for (int i = 0; i < chars.length; i++) {
edge[chars[i] - 0] = i;
edge[chars[i] - 'a'] = i;
}
int idx = 0;
int last = -1;
for (int i = 0; i < chars.length; i++) {
idx = Math.max(idx,edge[chars[i] - 0]);
idx = Math.max(idx,edge[chars[i] - 'a']);
if (i == idx) {
list.add(i - last);
last = i;