My clean python solution,


  • 1
    B
    def lengthOfLongestSubstring(self, s):
            map={}
            longest=0
            first=0
            for i in range(len(s)):
                if s[i] in map:
                    first=max(first,map[s[i]]+1)
                map[s[i]]=i
                longest=max(longest,i-first+1)
            
            return longest

Log in to reply
 

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