컴공생의 다이어리
[프로그래머스] 주식가격 - 파이썬(Python) 본문
[프로그래머스] 주식가격 - 파이썬(Python)
from collections import deque
def solution(prices):
queue = deque(prices)
answer = []
while queue:
price = queue.popleft()
sec = 0
for q in queue:
sec += 1
if price > q:
break
answer.append(sec)
return answer
https://programmers.co.kr/learn/courses/30/lessons/42584
코딩테스트 연습 - 주식가격
초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수를 완성하세요. 제한사항 prices의 각 가격은 1 이상 10,00
programmers.co.kr
728x90
반응형
'Development > Algorithm & Coding Test' 카테고리의 다른 글
[알고리즘] 너비 우선 탐색(BFS, Breadth First Search) (0) | 2022.05.13 |
---|---|
[알고리즘] 깊이 우선 탐색(DFS, Depth First Search) (0) | 2022.05.12 |
[프로그래머스] 다리를 지나는 트럭 - 파이썬(Python) (0) | 2022.05.10 |
[프로그래머스] 프린터 - 파이썬(Python) (0) | 2022.05.09 |
[프로그래머스] 기능개발 - 파이썬(Python) (0) | 2022.05.08 |
Comments