您的位置:首页 > 编程语言 > Python开发

Leetcode 3. Longest Substring Without Repeating Characters(python)

2016-03-27 20:40 513 查看
要判断最后一个不重复的子串是不是最长

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


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: