Skip to content

Commit

Permalink
s2_1874.py
Browse files Browse the repository at this point in the history
  • Loading branch information
haesol1013 committed Sep 8, 2024
1 parent 2b36917 commit 752a31e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 신해솔/s2_1874.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 스택 수열 - 1874

import sys
input = lambda: sys.stdin.readline().rstrip()


def stack(target: list[int]) -> str | list[str]:
seq: list[int] = list(range(len(target), 0, -1))
save: list[int] = []
result: list[str] = []

for i in target:
while True:
if save and save[-1] == i:
save.pop()
result.append("-")
break

if not seq:
return "NO"

save.append(seq.pop())
result.append("+")

return result


def main():
n = int(input())
target = [int(input()) for _ in range(n)]
result = stack(target)

if type(result) is list:
for i in result:
print(i)
else:
print(result)


if __name__ == "__main__":
main()

0 comments on commit 752a31e

Please sign in to comment.