Computer Science/Coding Test
프로그래머스: 주식 가격
focalpoint
2021. 10. 16. 01:09
근본 없는 문제다.
도저히 지문을 이해할 수 없게 적어놨다.
def solution(prices):
answer = [i for i in range(len(prices)-1, -1, -1)]
stack = []
for i in range(len(prices)):
p = prices[i]
if not stack or p >= stack[-1][0]:
stack.append((p, i))
else:
while stack and stack[-1][0] > p:
bef_p, bef_i = stack.pop()
answer[bef_i] = i - bef_i
stack.append((p, i))
return answer