Share my Python solution


  • 0
    W
    class Solution(object):
    
        def lengthOfLongestSubstring(self, s):
            ret = 0
            i = 0
            d = {}
            for j, c in enumerate(s):
                if d.get(c, -1) >= i:
                    i = d[c] + 1
                ret = max(ret, j - i + 1)
                d[c] = j
            return ret
    

Log in to reply
 

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