주식가격
코딩테스트 연습 > 스택/큐 > 주식가격
https://programmers.co.kr/learn/courses/30/lessons/42584
from collections import deque
prices = [1,2,3,2,3]
result = [] # Set initial vlaue
price = deque(prices) # Transform list to deque
while price:
cnt = 0 # Set local value
p1 = price.popleft() # pop first element
for p in price:
if p1 > p:
cnt = 1 # Count 1
break
cnt += 1
result.append(cnt)
prices = [1,2,3,2,3]
result = [0] * len(prices) # Set initial value
for i in range(len(prices)-1):
for j in range(i,len(prices)-1):
if prices[i] > prices[j]:
break
else:
result[i] += 1
from collections import deque
def solution(prices):
result = []
price = deque(prices)
while price:
cnt = 0
p1 = price.popleft()
for p in price:
if p1>p:
cnt += 1
break
cnt+=1
result.append(cnt)
return result
prices = [1,2,3,2,3]
solution(prices)
def solution(prices):
result = [0] * len(prices) # Make initial array
for i in range(len(prices)-1):
for j in range(i, len(prices)-1):
if prices[i] >prices[j]:
break
else:
result[i] +=1
return result
prices = [1,2,3,2,3]
solution(prices)