[3] leetcode characters without repeating the longest substring

A copy of their own ugly code, for the first time by himself (bah), then goose thief with a long time, shorten time to study tomorrow

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        if len(s)==0:
            return 0
        snum=0
        num=0
        s2=[]
        j=1
        i=0
        while(1>0):
            if s[i] not in s2:
                num=num+1
                s2.append(s[i])
                i=i+1
                if num>snum:
                    snum=num
            else:
                del s2
                s2 = []
                i=j
                j=j+1
                num=0
            if i > (len(s)-1):
                break
        return snum

 

Published 12 original articles · won praise 15 · views 9564

Guess you like

Origin blog.csdn.net/wind_day/article/details/104119374
Recommended