3. Longest Substring Without Repeating Characters

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        res=0
        left=0
        visited=[]
        for i in xrange(len(s)):
            if s[i] not in visited:
                visited.append(s[i])
                
            else: 
                while s[left]!=s[i]:
                    visited.remove(s[left])
                    left+=1
                left+=1 
            res=max(res,i-left+1)
        return res 

你可能感兴趣的:(3. Longest Substring Without Repeating Characters)