Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cashlo/9505289ee1861269de91eef8bd046087 to your computer and use it in GitHub Desktop.
Save cashlo/9505289ee1861269de91eef8bd046087 to your computer and use it in GitHub Desktop.
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
max_length = 0
seen_dict = {}
sub_start = 0
for i, c in enumerate(s):
if c in seen_dict:
sub_start = seen_dict[c]+1
for k, v in seen_dict.items():
if v < sub_start:
del seen_dict[k]
seen_dict[c] = i
if len(seen_dict) > max_length:
max_length = len(seen_dict)
return max_length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment