FrogRiverOne

 1         /// <summary>
 2         /// Solution
 3         /// 通过率 100%
 4         /// </summary>
 5         /// <param name="X"></param>
 6         /// <param name="A"></param>
 7         /// <returns></returns>
 8         public static int solution(int X, int[] A)
 9         {
10             bool[] flagArr = new bool[X];
11             for (int i = 0; i < A.Length; i++)
12             {
13                 if (flagArr[A[i] - 1] == false)
14                 {
15                     flagArr[A[i] - 1] = true;
16                     X--;
17                 }
18                 if (X == 0)
19                 {
20                     return i;
21                 }
22             }
23             return -1;
24         }
时间: 2024-10-05 04:19:28

FrogRiverOne的相关文章

[codility] Lesson 2

FrogRiverOne def solution(X, A): positions = set() for i in range(len(A)): if A[i] not in positions: positions.add(A[i]) if len(positions) == X: return i return -1