My clear Python solution


  • 0
    J
    class Solution(object):
    def lengthOfLongestSubstring(self, s):
        dict = collections.defaultdict(lambda: -1)
        id = -1
        res = 0
        for i, val in enumerate(s):
            id = max(id, dict[s[i] ])
            res = max(res, i-id)
            dict[s[i] ] = i
        return res

Log in to reply
 

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