Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment