1624. 两个相同字符之间的最长子字符串
java代码:
class Solution {
public int maxLengthBetweenEqualCharacters(String s) {
int[] hash = new int[26];
Arrays.fill(hash, -1); // fill是Arrays静态方法
int max = -1;
for (int i = 0; i < s.length(); ++i) { // 对立面:一边存,一边读
if (hash[s.charAt(i) - 'a'] == -1) {
hash[s.charAt(i) - 'a'] = i;
} else {
max = Math.max(max, i - hash[s.charAt(i) - 'a'] - 1);
}
}
return max;
}
}