mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 20:40:39 +08:00
fix(0763): 下标取 字母 - 'a' 的值,少点空间
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user