Python Solution


  • 0
    Y
    class Solution(object):
    def lengthOfLongestSubstring(self, s):
        head, max_len, s_dict = 0, 0, {} 
        for i, v in enumerate(s):
            if v in s_dict and s_dict[v] >= head:
                max_len = max(max_len, i - head)
                head = s_dict[v] + 1
            s_dict[v] = i
        return max(max_len, len(s) - head)

Log in to reply
 

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