Solution :
## 시간복잡도 최악의 경우 O(N^2)
from collections import deque
def solution(prices):
# 초기화
q_prices=deque(prices)
answer=[]
while q_prices:
count=0
temp_value=q_prices.popleft() # 값이 나오고.
for i in q_prices:
count+=1
if temp_value >i :
break
answer.append(count)
return answer
## 시간복잡도 더 빠름.
def solution(prices):
stack = []
answer = [0] * len(prices)
for i in range(len(prices)):
while stack != [] and stack[-1][1] > prices[i]: # 가장 최근 스택 가격> 현재 가격
print(stack)
past, _ = stack.pop()
answer[past] = i - past
stack.append([i, prices[i]])
for i, s in stack:
answer[i] = len(prices) - 1 - i
return answer
Skills :