Closed jihwankim128 closed 1 year ago
# 17298번 - 오큰수
import sys
input = sys.stdin.readline
n = int(input())
s = list(map(int, (input().split())))
stack = []
ans = [0 for i in range(n)]
stack.append(0)
for i in range(1, n):
if not stack:
s.append(i)
while stack and s[stack[-1]] < s[i]:
ans[stack[-1]] = s[i]
stack.pop()
stack.append(i)
while stack:
ans[stack[-1]] = -1
stack.pop()
print(*ans)
리스트를 여러개 쓰니 헷갈린다 이름을 잘 정리하자 본인보다 큰 숫자가 나올 때 까지 해당 인덱스를 push, 큰 숫자를 만나면 pop 하면서 정답 리스트에 값 넣기
3가지 질문으로 문제 해결
한번의 작업이 끝날 때 마다 현재 값은 스택에 삽입해야함.