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