题目:1624. 两个相同字符之间的最长子字符串
思路:
class Solution {
public:
int maxLengthBetweenEqualCharacters(string s) {
vector<int> letter(27,-1);
int res = -1;
int n = s.size();
for(int i=0; i<n; ++i){
if(letter[s[i]-'a']==-1){
letter[s[i]-'a']=i;
}else{
res = max(res,i-letter[s[i]-'a']-1);
}
}
return res;
}
};