LintCode:最长无重复字符的子串

LintCode:最长无重复字符的子串

class Solution:
    # @param s: a string
    # @return: an integer
    def lengthOfLongestSubstring(self, s):
        # write your code here
        L = []
        max_len = 0
        n = 0
        i = 0
        while i < len(s):
            for j in range(i, len(s)):
                if s[j] not in L:
                    L.append(s[j])
                    n += 1
                    if n > max_len:
                        max_len = n
                else:
                    tmp = L.index(s[j])
                    i += tmp
                    L = []
                    n = 0
                    break
            i += 1
        return max_len

你可能感兴趣的:(LintCode:最长无重复字符的子串)