首页 > 编程语言 > 详细

leetcode Longest Substring Without Repeating Characters python

时间:2015-11-06 22:13:28      阅读:291      评论:0      收藏:0      [点我收藏+]
class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        if len(s) <= 0:
            return 0
        res = list()
        maxLen = 0
        for i in s:
            if i in res:
                tmpLen = len(res)
                if tmpLen > maxLen:
                    maxLen = tmpLen
                while True:
                    tmp = res.pop(0)
                    if tmp == i:
                        break
                res.append(i)
            else:
                res.append(i)
        cnt = len(res)
        if cnt > maxLen:
            maxLen = cnt
        return maxLen

 

leetcode Longest Substring Without Repeating Characters python

原文:http://www.cnblogs.com/allenhaozi/p/4943608.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!