12 lines Python Solution


  • 0
    J

    """

        list = []
        length = 0
        for i,ch in enumerate(s) :
            if ch in list :
                index = list.index(ch)
                # index is the position of last repeated char
                if len(list) > length :
                    length = len(list)
                list = list[index+1:]
            list.append(ch)    
        if len(list) > length :
            length = len(list)
        return length
    

    """


Log in to reply
 

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