码迷,mamicode.com
首页 > 编程语言 > 详细

Leetcode 3. Longest Substring Without Repeating Characters(python)

时间:2016-03-27 21:16:39      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

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

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)

标签:

原文地址:http://www.cnblogs.com/colorss/p/5326735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!