leetcode Longest Substring Without Repeating Characters python

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

 

posted @ 2015-11-06 20:47  hao.ma  阅读(149)  评论(0编辑  收藏  举报