01 無重複字符最長子串
- 快慢指針
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
ans = 0
if not s:
return ans
i = 0
j = 0
dic = {}
while j < len(s):
if s[j] in dic:
i = max(dic[s[j]]+1,i)
dic[s[j]] = j
ans = max(ans,j-i+1)
j += 1
return ans