9-line simple python code


  • 1
    7
    def lengthOfLongestSubstring(self, s):
        hashtable = [-1] * 128
        left = maxlength = 0
        for right in range(0, len(s)):
            if hashtable[ord(s[right])] >= left:
                left = hashtable[ord(s[right])] + 1
            hashtable[ord(s[right])] = right
            maxlength = right - left + 1 if right - left + 1 > maxlength else maxlength
        return maxlength

Log in to reply
 

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