진박사의 일상

[프로그래머스] 큐 문제 - 주식 가격 본문

프로그래밍/코딩테스트 공부

[프로그래머스] 큐 문제 - 주식 가격

진박사. 2021. 9. 10. 08:14
from collections import deque
def solution(prices):
    prices = deque(prices) #deque화
    answer = []
    
    while prices:
        price = prices.popleft() #왼쪽에서 꺼냄
        period = 0
        for p in prices: 
            if p >= price: #우측 가격이 크거나 같으면
                period += 1 #기간 증가
            else: #달라지면 
                period += 1 #1초 증가후
                break #기간 끝
        answer.append(period)
        
    
    return answer

7분컷~ 이제 슬슬 쉬운 문제에서는 시간이 절약되고 있음.