snippets
filter:96 snippets
py-lc-longestsubstring·python·leetcode
class Solution:
def lengthOfLongestSubstring(self, s):
seen = {}
left = best = 0
for right, c in enumerate(s):
if c in seen and seen[c] >= left:
left = seen[c] + 1
seen[c] = right
best = max(best, right - left + 1)
return best
py-lc-longestsubstring·python·leetcode
class Solution:
def lengthOfLongestSubstring(self, s):
seen = {}
left = best = 0
for right, c in enumerate(s):
if c in seen and seen[c] >= left:
left = seen[c] + 1
seen[c] = right
best = max(best, right - left + 1)
return best