阅读背景:

leetcode-3.-无重复字符的最长子串及输出最长子串的长度 位置 子串_superXX07的博客

来源:互联网 
  • 方法一:暴力求解 会超时
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



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: