MinAvgTwoSlice【★★★★★】

 1         /// <summary>
 2         /// Solution
 3         /// 100/100
 4         /// </summary>
 5         /// <param name="A"></param>
 6         /// <returns></returns>
 7         public int solution(int[] A)
 8         {
 9             double avg = (A[0] + A[1]) / 2.0;
10             int index = 0;
11             for (int i = 1; i < A.Length - 2; i++)
12             {
13                 if ((A[i] + A[i + 1]) / 2.0 < avg)
14                 {
15                     index = i;
16                     avg = (A[i] + A[i + 1]) / 2.0;
17                 }
18                 if ((A[i] + A[i + 1] + A[i + 2]) / 3.0 < avg)
19                 {
20                     index = i;
21                     avg = (A[i] + A[i + 1] + A[i + 2]) / 3.0;
22                 }
23             }
24             if ((A[A.Length - 2] + A[A.Length - 1]) / 2.0 < avg)
25             {
26                 index = A.Length - 2;
27                 avg = (A[A.Length - 2] + A[A.Length - 1]) / 2.0;
28             }
29             return index;
30         }

 

你可能感兴趣的:(slice)