Lesson5 - PassingCars

作成日:2015/5/16
Task Score:100%
PassingCars coding task - Learn to Code - Codility

class Solution {
    public int solution(int[] A) {

        int count = 0;
        int est_cars = 0;

        for (int i = A.length-1; i > -1; i--) {
          if(A[i] == 1) {
            est_cars += 1;
          } else {
            count += est_cars;
            if(count > 1000000000) return -1;
          }
        }
        return count;
    }
}