标签:offer substr off solution dex targe lan code sub
begin为最长不含重复字符的子字符串的起点
1 class Solution: 2 def lengthOfLongestSubstring(self, s: str) -> int: 3 begin,ans,dic = 0,0,{} 4 for index,c in enumerate(s): 5 if c in dic: 6 begin = max(dic[c] + 1,begin) 7 dic[c] = index #更新字符c的坐标为当前坐标 8 ans = max(index - begin + 1, ans) 9 return ans
标签:offer substr off solution dex targe lan code sub
原文地址:https://www.cnblogs.com/lj95/p/14320526.html