사용언어 : python
deque
의popleft()
함수를 이용
prices[0]를 i에 저장
for문을 이용하여 for문이 반복될 때마다 time +=1을 해주고,
만약 y가 i보다 작으면 break를 해주었다.
answer.append(time-1)에서 -1을 한 이유가 for문이 i값을 포함하여 돌기 때문이다.
from collections import deque
def solution(prices):
prices = deque(prices)
answer= []
while 1:
i = prices[0]
time = 0
if len(prices) == 1:
answer.append(0)
break
for y in prices:
time+=1
if y < i:
break
answer.append(time-1)
prices.popleft()
return answer