본문 바로가기
프로그래머스

Level2 주식가격

by ysunee 2022. 2. 3.
def solution(prices):
    stack = []
    n = len(prices)
    d = [n-i-1 for i in range(n)]
    
    for i in range(n):
        if(len(stack)==0): stack.append([prices[i],i])
        else:
            while True:
                if(len(stack)==0): stack.append([prices[i],i]); break
                top = stack[-1]
                if(top[0]>prices[i]): stack.pop(); d[top[1]]=(i-top[1])
                elif(top[0]<=prices[i]): stack.append([prices[i],i]); break     
                else: break    
    return d

'프로그래머스' 카테고리의 다른 글

Level2 모음사전  (0) 2022.02.03
Level2 구명보트  (0) 2022.02.03
Level2 영어 끝말잇기  (0) 2022.02.02
Level1 폰켓몬  (0) 2022.02.02
Level1 체육복  (0) 2022.02.02

댓글