[파이썬/python] 백준 1874번 : 스택 수열(🥈2)

 

 

풀이

import sys
input = sys.stdin.readline

stack = []
op = []
cnt = 1

for i in range(int(input())):
    n = int(input())
    
    while cnt < n + 1:
        stack.append(cnt)
        cnt += 1
        op.append("+")
        
    if stack[-1] == n:
        stack.pop()
        op.append("-")


if len(stack) > 0:
    print("NO")
else:
    for i in op:
        print(i)

 

comment