leetcode-1624. 两个相同字符之间的最长子字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public int maxLengthBetweenEqualCharacters(String s) {
int n = s.length();
int max = -1;
for (int i = 0; i < n; i++) {
for (int j = n - 1; j > i; j--) {
if (s.charAt(i) == s.charAt(j)){
max = Math.max(max, j - i - 1);
}
}
}
return max;
}
}