class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        if len(s) <= 0:
            return 0
        res = list()
        maxLen = 0
        for i in s:
            if i in res:
                tmpLen = len(res)
                if tmpLen > maxLen:
                    maxLen = tmpLen
                while True:
                    tmp = res.pop(0)
                    if tmp == i:
                        break
                res.append(i)
            else:
                res.append(i)
        cnt = len(res)
        if cnt > maxLen:
            maxLen = cnt
        return maxLen

 

相关文章:

  • 2021-08-01
  • 2022-02-13
  • 2021-08-03
  • 2022-01-06
  • 2022-01-20
  • 2021-05-25
猜你喜欢
  • 2021-12-20
  • 2021-09-13
  • 2021-09-11
  • 2021-08-28
  • 2021-10-04
相关资源
相似解决方案