#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param arr int整型一维数组 the array
# @return int整型
#
class Solution:
def maxLength(self , arr: List[int]) -> int:
# write code here
if not arr:
return 0
left = 0
maxLen = 0
hashMap = {}
for right in range(len(arr)):
if arr[right] in hashMap:
left = max(left, hashMap[arr[right]] + 1)
hashMap[arr[right]] = right
maxLen = max(maxLen, right - left + 1)
return maxLen



京公网安备 11010502036488号