문제: app.codility.com/programmers/lessons/5-prefix_sums/min_avg_two_slice/
double minAvg = (A[0] + A[1]) / 2.0;
int result = 0;
for (int i = 2; i < A.Length; i++)
{
double avg = (A[i] + A[i - 1] + A[i - 2]) / 3.0;
if (minAvg > avg)
{
minAvg = avg;
result = i - 2;
}
avg = (A[i] + A[i - 1]) / 2.0;
if (minAvg > avg)
{
minAvg = avg;
result = i - 1;
}
}
return result;
'공부하자 > Codility' 카테고리의 다른 글
[Codility] Lesson6. Distinct (C#) (0) | 2020.11.20 |
---|---|
[Codility] Lesson5. PassingCars (C#) (0) | 2020.11.17 |
[Codility] Lesson5. GenomicRangeQuery (C#) (0) | 2020.11.17 |
[Codility] Lesson5. CountDiv (C#) (0) | 2020.11.17 |
[Codility] Lesson4. PermCheck (C#) (0) | 2020.11.17 |