Created
July 20, 2018 08:12
-
-
Save cashlo/a34b48de53fc5c5429b31b9bbe8413e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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