Programmers / 2단계 / [스택/큐] 주식가격 / python
·
Coding Test/Programmers
코딩테스트 연습 - 주식가격 | 프로그래머스 스쿨 (programmers.co.kr) 나의 풀이 . 모범 답안 def solution(prices): length = len(prices) # 모든 가격 max값으로 세팅 result = [ i for i in range (length - 1, -1, -1)] # 주식 가격이 떨어지는 경우를 찾아 수정 stack = [0] for i in range (1, length): while stack and prices[stack[-1]] > prices[i]: j = stack.pop() result[j] = i - j stack.append(i) return result 1. 모든 가격 max값으로 세팅: result=[4,3,2,1,0] 2. 가격이 떨어지는..