public int solution(int[] cookie) {
int answer = 0;
for (int i = 0; i < cookie.length - 1; i++) {
int firstIndex = i;
int secondIndex = i + 1;
int firstSum = cookie[firstIndex];
int secondSum = cookie[secondIndex];
while (true) {
if (firstSum == secondSum) {
answer = Math.max(answer, secondSum);
}
if (firstSum <= secondSum && firstIndex > 0) {
firstSum += cookie[--firstIndex];
} else if (firstSum > secondSum && secondIndex < cookie.length - 1) {
secondSum += cookie[++secondIndex];
} else {
break;
}
}
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/49995