LeetCode 1624两个相同字符之间的最长子字符串(java)
程序员文章站
2022-07-13 17:48:00
...
class Solution {
public int maxLengthBetweenEqualCharacters(String s) {
int size = s.length();
int res = -1;
for(int start = 0; start < size - 1; start++) {
for(int end = start + 1; end < size; end++) {
char [] sb = s.toCharArray();
if(sb[start] == sb[end])
res = Math.max(res, end - start - 1);
}
}
return res;
}
}