python concise and simple code


  • 0
    C
        def lengthOfLongestSubstring(self, s):
            if not s:
                return 0
            maxl,j,i = 0,0,0
            dic = dict([(s[0],0)])
            while i < len(s) and j < len(s):
                if s[j] in dic and j > dic[s[j]] >= i:
                    i += 1
                else:
                    dic[s[j]] = j
                    j += 1
                maxl = max(j - i, maxl)
            return maxl

Log in to reply
 

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