Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
答案;
class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
dct = {}
max_so_far = curr_max = start = 0
for index, i in enumerate(s):
if i in dct and dct[i] >= start:
max_so_far = max(max_so_far, curr_max)
curr_max = index - dct[I]
start = dct[i] + 1
else:
curr_max += 1
dct[i] = index
return max(max_so_far, curr_max)