my python solution


  • 0
    M

    class Solution(object):

    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        l,ans=[],[]
        for i in s:
            if i in l:
                p=l.index(i)
                l.append(i)
                l=l[p+1:]
            else:
                l.append(i)
            if len(l) > len(ans):
                ans=l[:]
        return len(ans)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.