Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cashlo/a34b48de53fc5c5429b31b9bbe8413e2 to your computer and use it in GitHub Desktop.
Save cashlo/a34b48de53fc5c5429b31b9bbe8413e2 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:
for j in range(sub_start, seen_dict[c]):
del seen_dict[s[j]]
sub_start = seen_dict[c]+1
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