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