문제풀이/백준(Boj) 문제풀이

[백준][스택] 17298. 오큰수 (파이썬/Python)

얄루몬 2021. 11. 16. 17:56

import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
answer = [-1] * n
stack = []


stack.append(0)
for i in range(1, n):
    while stack and a[stack[-1]] < a[i]:
        answer[stack.pop()] = a[i]
    stack.append(i)


print(*answer)