Short accepted python solution


  • 2
    T
     def lengthOfLongestSubstring(self, s):
            ch2idx = {};
            maxLen = resStart = 0;
            for i, ch in enumerate(s):
                if ch in ch2idx:
                    maxLen = max(maxLen, i - resStart);
                    resStart = max(resStart, ch2idx[ch] + 1);
                ch2idx[s[i]] = i;
            return max(maxLen, len(s) - resStart);

Log in to reply
 

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