mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
17 lines
249 B
Go
17 lines
249 B
Go
package leetcode
|
|
|
|
import "strings"
|
|
|
|
func maxLengthBetweenEqualCharacters(s string) int {
|
|
res := -1
|
|
for k, v := range s {
|
|
tmp := strings.LastIndex(s, string(v))
|
|
if tmp > 0 {
|
|
if res < tmp-k-1 {
|
|
res = tmp - k - 1
|
|
}
|
|
}
|
|
}
|
|
return res
|
|
}
|