码迷,mamicode.com
首页 > 其他好文 > 详细

Longest Substring Without Repeating Characters

时间:2016-10-06 22:18:28      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

题目如下:

技术分享

Python代码:

class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        string = []
        length = 0
        max = 0
        for i in range(len(s)):
            if s[i] not in string:
                string.append(s[i])
            else:
                pos = string.index(s[i])
                if pos<len(string)-1:
                    string = string[string.index(s[i])+1:]
                else:
                    string = []
                string.append(s[i])
            if len(string)>max:
                max = len(string)
        return max

 

Longest Substring Without Repeating Characters

标签:

原文地址:http://www.cnblogs.com/CQUTWH/p/5934616.html

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