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 min = Integer.MAX_VALUE; int sumOfSecondPart = 0; for (int a : A) { sumOfSecondPart += a; } int sumOfFirstPart = 0; for (int i = 0; i < A.length - 1; i++) { sumOfFirstPart += A[i]; sumOfSecondPart -= A[i]; // System.out.println(sumOfFirstPart+" "+sumOfSecondPart); min = Math.min(Math.abs(sumOfFirstPart - sumOfSecondPart), min); // System.out.println(min); } return min; } | cs |
'알고리즘 풀이 > Codility' 카테고리의 다른 글
codility - Counting Elements (MaxCounters) (0) | 2019.12.10 |
---|---|
codility - Counting Elements (FrogRiverOne) (0) | 2019.12.10 |
codility - Time Complexity (PermMissingElem) (0) | 2019.12.10 |
codility - Time Complexity (FrogJmp) (0) | 2019.12.10 |
codility - Arrays (CyclicRotation) (0) | 2019.12.09 |