def Solution(s):
start=-1
max=0
dir={}
for i in range(len(s)):
if s[i] in d and d[s[i]]>start:
start=d[s[i]]
d[s[i]]=i
else:
d[s[i]]=i
if i-start>max:
max=i-start
return max
Longest Substring Without Repeating Character
最新推荐文章于 2025-12-22 13:59:14 发布
本文介绍如何使用Python实现一个名为Solution的函数,该函数通过动态规划求解给定字符串中最长无重复字符的子串长度。核心算法利用字典跟踪字符最后出现的位置,以找到最远距离的重复字符起点。
708

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



