首页 > 代码库 > Longest Substring Without Repeating Characters

Longest Substring Without Repeating Characters

题目如下:

技术分享

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