class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
res = 0
if s is None or len(s) == 0:
return res
ht = {}
temp = 0
start = 0
for i in range(len(s)):
if s[i] in ht and ht[s[i]] >= start:
start = ht[s[i]] + 1
temp = i - start + 1
ht[s[i]] = i
res = max(res, temp)
return res
Python, LeetCode, 3. 无重复字符的最长子串
最新推荐文章于 2024-11-10 10:02:01 发布