Skip to content

Commit 4189797

Browse files
committed
115차 2번 문제풀이(참고)
1 parent 7245a24 commit 4189797

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
4+
input = sys.stdin.readline
5+
6+
n = int(input())
7+
a = list(map(int, input().split()))
8+
9+
stack = []
10+
res = [-1] * n
11+
for i in range(n - 1, -1, -1): # 역순으로
12+
while stack and stack[-1] <= a[i]:
13+
stack.pop()
14+
15+
if stack:
16+
res[i] = stack[-1]
17+
18+
stack.append(a[i])
19+
20+
print(*res)
21+
22+
23+
"""
24+
4
25+
3 5 2 7
26+
"""

0 commit comments

Comments
 (0)