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

题目描述:

 

 提交:

class Solution:
    def maxLengthBetweenEqualCharacters(self, s: str) -> int:
        dic = {}
        res = -1
        for i,v in enumerate(s):
            if v not in dic:
                dic[v] = i
            else:
                res = max(res,i - dic[v] - 1)
        return res

 

posted @ 2020-10-18 12:18  oldby  阅读(158)  评论(0编辑  收藏  举报