
초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요.
| prices | return | 
|---|---|
| [1, 2, 3, 2, 3] | [4, 3, 1, 1, 0] | 
def solution(prices):
    answer=[]
    while prices:
        check=prices.pop(0)
        if any (check > i for i in prices):
            for i in prices:
                if check>i:
                    answer.append(prices.index(i)+1)
                    break
        else:
            answer.append(len(prices))
    return answer
def solution(prices):
    answer = [0] * len(prices)
    for i in range(len(prices)):
        for j in range(i+1, len(prices)):
            answer[i] += 1
            if prices[i] > prices[j]: break
    return answer

from collections import deque
def solution(prices):
    answer = []
    prices = deque(prices)
    while prices:
        c = prices.popleft()
        count = 0
        for i in prices:
            if c > i:
                count += 1
                break
            count += 1
        answer.append(count)
    return answer
이 문제는 스택/큐 문제여서 큐를 이용한 풀이들이 많았는데 결과를 보면 확실히 효율성이 더 좋은 것을 볼 수 있다!

자료구조 다시 공부해야 하는데...
출처: 프로그래머스
오류가 있으면 댓글 달아주세요🙂