Skip to content

Commit 3d10b02

Browse files
author
hangyeol
committed
98차 3번 문제 풀이
1 parent 5e91e0e commit 3d10b02

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

live9/test98/문제3/백한결.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def solution(prices):
2+
answer = [0] * len(prices)
3+
4+
stack = []
5+
6+
for i, price in enumerate(prices):
7+
# 가격이 떨어지는 순간을 찾고 그 때까지의 시간을 계산
8+
while stack and prices[stack[-1]] > price:
9+
j = stack.pop()
10+
answer[j] = i - j
11+
stack.append(i)
12+
13+
# for문이 끝난 후 떨어지지 않은 가격
14+
while stack:
15+
j = stack.pop()
16+
answer[j] = len(prices) - (j + 1)
17+
18+
return answer

0 commit comments

Comments
 (0)