python 无重复字符的最长子串

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        temp = ''
        length = 0
        for i in s:
            if i not in temp:
                temp+=i
                length = max(length,len(temp))
            else:
                temp+=i
                
                kk=temp.index(i)
                print('kk=',kk)
                temp = temp[kk+1:]
            print(temp)
            
        return length

    
a='baaaabcdea'

c=Solution()

c1=c.lengthOfLongestSubstring(a)

print(c1)
posted @ 2022-08-19 22:49  luoganttcc  阅读(15)  评论(0)    收藏  举报