using System;
using System.Collections.Generic;
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param arr int整型一维数组 the array
* @return int整型
*/
public int maxLength (List<int> arr) {
// write code here
Dictionary<int, int> dic=new Dictionary<int,int>();
int res=0;
for(int l=0,r=0;r<arr.Count;r++)
{
if(dic.ContainsKey(arr[r])) dic[arr[r]]++;
else dic.Add(arr[r], 1);
while(dic[arr[r]]>1)
{
dic[arr[l++]]--;
}
res=Math.Max(res, r-l+1);
}
return res;
}
}

京公网安备 11010502036488号