3. Longest Substring Without Repeating Characters
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
n = len(s)
table = {}
imin = -1
imax = 0
res = 0
for i,c in enumerate(s):
if c in table:
imin = max(imin, table[c])
table[c] = i
res = max(res, i - imin)
else:
table[c] = i
# res = max(res, i - imin)
res = max(res, n - 1 - imin)
return res
主要的疏忽在于 最近的重复指针的更新。