3.无重复的最长子串

思路:双指针

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        l = 0
        r = 0
        res = 0
        while r<=len(s)-1:
            if s[r] not in s[l:r]:
                cur =  r-l+1
            else:
                l += s[l:r].index(s[r])+1
                cur = r-l+1
            #print(l,r,cur)
            r += 1
            res = max(res,cur)
        return res

你可能感兴趣的:(3.无重复的最长子串)