public int solution(int[] a) {
int answer = 0;
int leftMin = 1000000001;
int rightMin = 1000000001;
int n = a.length;
for (int i = 0; i < n; i++) {
if (a[i] < leftMin) {
leftMin = a[i];
answer++;
}
if (a[n - i - 1] < rightMin) {
rightMin = a[n - i - 1];
answer++;
}
if (leftMin == rightMin) {
break;
}
}
if (leftMin == rightMin) {
answer--;
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/68646