题解 | #最长无重复子数组#
最长无重复子数组
http://www.nowcoder.com/practice/b56799ebfd684fb394bd315e89324fb4
最长无重复子数组
# # # @param arr int整型一维数组 the array # @return int整型 # class Solution: def maxLength(self , arr ): # write code here n = len(arr) if n <= 1: return n hashMap = {} lo, hi = 0, 0 res = 0 while hi < n: curr = arr[hi] if curr not in hashMap: hashMap[curr] = 1 else: while hashMap.has_key(curr) and lo<=hi: del hashMap[arr[lo]] lo += 1 hashMap[curr] = 1 res = max(res, hi-lo+1) hi += 1 return res