728x90
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public int solution(int[] A) { // write your code in Java SE 8 int accum = 0; int sum = 0; for (int i = A.length - 1; i >= 0; i--) { if (A[i] == 1) accum++; else sum += accum; if(sum>1000000000) return -1; } return sum; } | cs |
'알고리즘 풀이 > Codility' 카테고리의 다른 글
codility - MinAvgTwoSlice (Prefix Sums) (0) | 2019.12.13 |
---|---|
codility - GenomicRangeQuery (Prefix Sums) (0) | 2019.12.10 |
codility - Counting Elements (MissingInteger) (0) | 2019.12.10 |
codility - Counting Elements (PermCheck) (0) | 2019.12.10 |
codility - Counting Elements (MaxCounters) (0) | 2019.12.10 |