초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요.
prices return
[1, 2, 3, 2, 3] [4, 3, 1, 1, 0]
Code_1 - 실행 오류
from collections import deque def solution(prices): answer = [] prices = deque(prices) while prices: t = -1 min = prices[0] for idx in range(len(prices)): if min <= prices[idx]: t += 1 answer.append(t) prices.popleft() return answer
Code_2 - 성공
from collections import deque def solution(prices): answer = [] prices = deque(prices) while prices: t = 0 price = prices.popleft() for p in prices: t += 1 if price > p: break answer.append(t) return answer