문제
https://school.programmers.co.kr/learn/courses/30/lessons/154539
코드
import java.util.*;
class Solution {
public int[] solution(int[] numbers) {
int[] answer = new int [numbers.length];
Stack<Integer> stack = new Stack<>();
stack.push(0);
for(int i=1;i<numbers.length;i++){
while(!stack.empty() && numbers[i] > numbers[stack.peek()]){
answer[stack.pop()] = numbers[i];
}
stack.add(i);
}
for(int i=0;i<answer.length;i++){
if(answer[i] == 0) answer[i] = -1;
}
return answer;
}
}