- 方法一:暴力求解 会超时
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
tmp_dict = {'max_str':'','start_index':0,'max_lenght':0}
n = len(s)
for i in range(n):
tmp_str = s[i]
for j in range(i+1,n):
if s[j] not in tmp_str:
tmp_str +=s[j]
else:
break
lenght = len(tmp_str)
if lenght > tmp_dict['max_lenght']:
tmp_dict = {'max_str':tmp_str,'start_index':i,'max_lenght':lenght}
return tmp_dict['max_lenght']
class Solution(obj