Share my python solution using dictionary

  • 1
    class Solution:
    # @return an integer
    def lengthOfLongestSubstring(self, s):
        dict = {}
        res,cur = 0,-1
        for i,c in enumerate(s):
            if c in dict and dict[c] > cur:
                cur = dict[c]
            dict[c] = i
            res = max(res,i - cur)
        return res

  • 0

    sorry,i can not understand the variant "cur", may you explain it to in detail? thanks a lot

Log in to reply

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