programmers | Lv2. ์ฃผ์‹๊ฐ€๊ฒฉ [Python]

yeonkยท2022๋…„ 3์›” 29์ผ
0

algorithm

๋ชฉ๋ก ๋ณด๊ธฐ
80/88
post-thumbnail

๐Ÿ’ก Python 3






๐Ÿ”— ๋ฌธ์ œ

์ฃผ์‹๊ฐ€๊ฒฉ [Link]






๐Ÿ’ป ์ฝ”๋“œ

def solution(prices):
    answer, stack = [0] * len(prices), []
    for i, p in enumerate(prices):
        while stack and p < prices[stack[-1]]:
            j = stack.pop()
            answer[j] = i - j
        stack.append(i)
        
    while stack:
        k = stack.pop()
        answer[k] = len(prices) - (1+k)
    return answer

0๊ฐœ์˜ ๋Œ“๊ธ€