반응형
코딩테스트 고득점 Kit 스택/큐 문제 풀이
import collections
def solution(progresses, speeds):
# 진행 상황을 기록하는 큐
progress_que = collections.deque(progresses)
# progress 증가 속도를 기록하는 큐
speed_que = collections.deque(speeds)
days = 0
answer = []
# 큐가 빌 때까지 실행.
while len(progress_que):
first_feature = progress_que.popleft()
speed = speed_que.popleft()
# 첫 번째로 큐에 들어간(중요도 높은) 기능이 모두 진행이 된 경우
if speed * days + first_feature >= 100:
count = 1
# 연속된 기능들이 개발 완료 되었는지 체크하기.
while len(progress_que):
p = progress_que.popleft()
s = speed_que.popleft()
if p + days * s >= 100:
count +=1
continue
# 아직 완성 안된 부분이 있으면 카운트 종료. 다시 큐의 왼쪽에 복구.
else:
progress_que.appendleft(p)
speed_que.appendleft(s)
break
answer.append(count)
# 제일 중요한 기능 개발이 완성 안된 경우 다시 큐에 집어 넣고 진행.
else:
progress_que.appendleft(first_feature)
speed_que.appendleft(speed)
days += 1
return answer
반응형
'개발 > 알고리즘' 카테고리의 다른 글
[프로그래머스] 더 맵게 (0) | 2022.03.02 |
---|---|
[프로그래머스] 주식가격 (0) | 2022.03.02 |
[프로그래머스] 프린터 (0) | 2022.02.28 |
[프로그래머스] 다리를 지나는 트럭 (0) | 2022.02.28 |