Python solution 100ms


  • 0
    B
    class Solution:
        def lengthOfLongestSubstring(self, s):
            uniqueC = {}
            maxlength=0
            start=0
            for i in range(len(s)):
                if (len(s)-start+1)<maxlength:
                    return maxlength
                if s[i] in uniqueC and start<=uniqueC[s[i]]:
                    start=uniqueC[s[i]]+1
                else:
                    maxlength=max(maxlength,i-start+1)
                uniqueC[s[i]]=i
            return maxlength
    

Log in to reply
 

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