Short'n'Sweet Python solution, beats 99%


  • 7
    class Solution(object):
        def lengthOfLongestSubstring(self, s):
            last, res, st = {}, 0, 0
            for i, v in enumerate(string):
                if v not in last or last[v] < st:
                    res = max(res, i - st + 1)
                else:
                    st = last[v] + 1
                last[v] = i
            return res

  • 0
    This post is deleted!

  • 0
    This post is deleted!

Log in to reply
 

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