欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

LeetCode 1624两个相同字符之间的最长子字符串(java)

程序员文章站 2022-07-13 17:48:00
...

LeetCode 1624两个相同字符之间的最长子字符串(java)

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;
    }
}
相关标签: LeetCode刷题系列