首页 > 技术文章 > Leetcode 3. Longest Substring Without Repeating Characters(python)

colorss 2016-03-27 20:40 原文

要判断最后一个不重复的子串是不是最长

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        if len(s)<=1:
            return len(s)
        point=0
        maxl=0
        for index in range(1,len(s)):
            if s[index] in s[point:index]:
                l=index-point
                if l>=maxl:
                    maxl=l
                point+=s[point:index].index(s[index])+1
        if index-point+1>maxl:
            maxl=index-point+1

        return maxl

  

 

推荐阅读