Python
遍历列表,采用字典存放正在查找的子串。无重复添加到字典;有重复,获取重复值的前一个下标,其后位置到当前下标更新至字典。
class Solution: def maxLength(self , arr ): # write code here dic = {arr[0]: 0} len_max = 1 for i in range(1, len(arr)): if arr[i] not in dic: dic[arr[i]] = i else: len_max = max(len_max, len(dic)) j = dic[arr[i]] dic = {arr[a]: a for a in range(j+1, i+1)} len_max = max(len_max, len(dic)) return len_max