class Solution(object):
def lengthOfLongestSubstring(self, s):
dict={}
res=0
start=0
for i,ch in enumerate(s):
if ch in dict:
res=max(res,i-start)
start=max(start, dict[ch]+1)
dict[ch]=i
return max(res,len(s)-start)注意enumerate 的用法
本文介绍了一种高效的算法来寻找给定字符串中最长的无重复字符子串,并通过Python实现。该算法利用字典记录字符出现的位置,结合滑动窗口技术更新最长子串的长度。
707

被折叠的 条评论
为什么被折叠?



