lc3. 无重复字符的最长子串
作者:互联网
class Solution: def lengthOfLongestSubstring(self, s: str) -> int: if len(s) < 2: return len(s) max_length = 0 i = 0 slide_window = {} while i < len(s):
# 遇到重复元素时,滑动窗口重置到重复元素的下一个元素 if s[i] in slide_window.keys(): max_length = max(max_length, len(slide_window)) i = slide_window[s[i]] + 1 slide_window.clear() slide_window[s[i]] = i i += 1 return max(max_length, len(slide_window))
标签:子串,字符,return,lc3,max,slide,len,window,length 来源: https://www.cnblogs.com/bidesen/p/16226786.html