Python simple but slow solution


  • 0
    A
    class Solution(object):
        def lengthOfLongestSubstring(self, s):
            """
            :type s: str
            :rtype: int
            """
            
            if len(s) < 1:
                return 0
    
            htab = {}
            lsub = 0
            i = 0
            while i < len(s):
    
                if s[i] in htab:
                    i = htab[s[i]]
                    lsub = max(lsub,len(htab))
                    htab = {}
                else:
                    htab[s[i]] = i
                i+=1
                
            return max(lsub, len(htab))
        
    

Log in to reply
 

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