Skip to content

Commit 0166c1e

Browse files
committed
117차 1번 문제풀이
1 parent 51d6357 commit 0166c1e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
5+
n = int(input())
6+
towers = list(map(int, input().split()))
7+
8+
stack = [] # 탑 번호
9+
res = [0] * n
10+
11+
for i in range(n):
12+
while stack and towers[stack[-1]] < towers[i]: # 왼쪽 탑이 더 낮으면
13+
stack.pop()
14+
if stack:
15+
res[i] = stack[-1] + 1
16+
stack.append(i)
17+
print(*res)
18+

0 commit comments

Comments
 (0)