class Solution {
public:
int maxLengthBetweenEqualCharacters(string s) {
//枚举所有a-z中,记录下每个元素出现的最大最小下标,之后输出最大res即可
int res = -1;
for(char c = 'a';c <= 'z';++c){
int l = s.size(),r = 0;
for(int i = 0;i < s.size();++i)
if(s[i] == c){
l = min(l,i);
r = max(r,i);
}
res = max(res,r - l - 1);
}
return res;
}
};