Leetcode 3. Longest Substring Without Repeating Characters(python)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 3. Longest Substring Without Repeating Characters(python)相关的知识,希望对你有一定的参考价值。

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

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

  

 

以上是关于Leetcode 3. Longest Substring Without Repeating Characters(python)的主要内容,如果未能解决你的问题,请参考以下文章

Leetcode 3. Longest Substring Without Repeating Characters

LeetCode 3. Longest Substring Without Repeating

3. 没有重复字母的最长子串 [leetcode 3: Longest Substring Without Repeating Characters]

3. 没有重复字母的最长子串 [leetcode 3: Longest Substring Without Repeating Characters]

leetcode longest consecutive sequence

leetcode 3. Longest Substring Without Repeating Characters (Python版)