Find longest substring and Count [python]


  • 0
    P

    class Solution(object):
    def lengthOfLongestSubstring(self, s):

        test=[]
        ans=0
        for g in range(len(s)):
            if s[g] not in test:
                test.append(s[g])
    
            else:
                index=test.index(s[g])
                test=test[index:len(test)]
                test.remove(s[g])
                test.append(s[g])
            ans=max(ans,len(test))
        return ans

Log in to reply
 

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