728x90
SMALL
안녕하세요 남갯입니다.
public class TapeEquilibrium {
public int solution(int[] A) {
// write your code in Java SE 8
int start =0;
int reverse = 0;
int min = Integer.MAX_VALUE;
for(int sum : A){
reverse += sum;
}
for(int i = 0; i < A.length-1; i++){
start += A[i];
reverse -= A[i];
if(Math.abs(start - reverse) < min) {
min = Math.abs(start - reverse);
}
}
return min;
}
}
728x90
LIST
'IT > 알고리즘' 카테고리의 다른 글
[코딜리티] - Lesson 4. MaxCounters (0) | 2019.08.12 |
---|---|
[코딜리티] - Lesson 4. FrogRiverOne (0) | 2019.08.12 |
[코딜리티] - Lesson 3. PermMissingElem (0) | 2019.08.05 |
[코딜리티] - Lesson 3. FrogJmp (0) | 2019.08.05 |
[코딜리티] - Lesson 2. CyclicRotation (0) | 2019.07.29 |