Codility – Lesson 5 Prefix Sums – MinAvgTwoSlice
プログラミング能力を評価するオンラインテスト、Codilityで、Lesson 5 Prefix Sums – MinAvgTwoSliceに回答しました。
問題と結果画面
50%の評価。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
using System; class Solution { public int solution(int[] A) { float smallestNum = A[0]; int index = 0; for (int i = 0; i < (A.Length - 1); i++) { float tmp = (A[i] + A[i + 1]) / 2; if (tmp < smallestNum) { smallestNum = tmp; index = i; } } return index; } } |