leetcode【3】最长不重复子串----【Python】【字典】

问题描述

给定一串字符串,输出最长不重复的子串

输入输出

代码实现

class Solution:
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        temp = 0
        d = {}
        start = 0 
        for i in range(len(s)):
            if s[i] in d and start <= d[s[i]] :
                start = d[s[i]] +1
            temp = max(i-start+1,temp)
            d[s[i]] = i
        return temp

 


版权声明:本文为weixin_42702666原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。