Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DataSolveProblems/566c6426baf07e992f8c15229a47469b to your computer and use it in GitHub Desktop.
Save DataSolveProblems/566c6426baf07e992f8c15229a47469b to your computer and use it in GitHub Desktop.
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
mapper = {}
start = 0
longest = 0
for i, c in enumerate(s):
if c in mapper and mapper[c] >= start:
start = mapper[c] + 1
else:
longest = max(longest, i - start + 1)
mapper[c] = i
return longest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment