class Solution:
def lengthOfLongestSubstring(self, s: str):
start = -1
max = 0
d ={}
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
leetcode | 3 Longest Substring Without Repeating Characters
于 2022-03-31 09:25:38 首次发布