MaxCounters
1 /// <summary> 2 /// Solution 3 /// 100/100 4 /// </summary> 5 /// <param name="N"></param> 6 /// <param name="A"></param> 7 /// <returns></returns> 8 public int[] solution(int N, int[] A) 9 { 10 int[] arr = new int[N]; 11 int max = 0; 12 int baseNum = 0; 13 14 foreach (int num in A) 15 { 16 if (num != N + 1) 17 { 18 if (arr[num - 1] < baseNum) 19 arr[num - 1] = baseNum; 20 arr[num - 1]++; 21 if (arr[num - 1] > max) 22 max = arr[num - 1]; 23 } 24 else 25 { 26 baseNum = max; 27 } 28 } 29 30 for (int i = 0; i < arr.Length; i++) 31 { 32 if (arr[i] < baseNum) 33 arr[i] = baseNum; 34 } 35 36 return arr; 37 }