问题描述

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

输入输出

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

 

相关文章:

  • 2021-12-18
  • 2021-08-17
  • 2021-08-10
  • 2021-05-30
  • 2021-11-30
  • 2021-06-08
  • 2021-07-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2021-11-05
  • 2021-04-15
  • 2021-10-18
  • 2021-04-06
相关资源
相似解决方案