class Solution {
public:
int maxLengthBetweenEqualCharacters(string s
) {
vector
<int> a
[26];
for (int i
= 0; i
< s
.size(); i
++)
a
[s
[i
] - 'a'].emplace_back(i
);
int ans
= -1;
for (auto x
: a
)
if (x
.size() > 1) ans
= max(ans
, x
.back() - x
.front());
return ans
;
}
};
转载请注明原文地址: https://lol.8miu.com/read-20391.html