본문 바로가기

IT/알고리즘

[코딜리티] - Lesson 3. TapeEquilibrium

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