초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요.
| prices | return |
|---|---|
| [ 1, 2, 3, 2, 3 ] | [ 4, 3, 1, 1, 0 ] |
def solution(prices):
answer = []
queue = []
idx = 0
for i in range(len(prices)):
sec = 0
for j in range(i+1, len(prices)):
sec += 1
if prices[i] > prices[j]:
break
answer.append(sec)
return answer
처음에 index값으로 계산할려고 하니 쉽지 않았다. 그래서 초를 세며 값을 구해가니 쉽게 해결할 수 있었다.