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

问题描述

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

输入输出

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