본문 바로가기
코딩테스트/프로그래머스

[프로그래머스] LV2 기능개발 | 파이썬

by 애플파ol 2025. 5. 7.

Solution :

import math
from collections import deque
def solution(progresses, speeds):
    # [1] 남은 일 수 구하기
    days=[math.ceil((100-i)/k) for i,k in zip(progresses,speeds)]
    # print(days)
    
    # 초기화
    answer = []
    q_days=deque(days)
    current_day=q_days.popleft()
    count=1
    
    # [2] while 반복문 돌림 + 누적O 및 누적X
    while q_days:             
        if q_days and current_day >= q_days[0]: # 누적O
            q_days.popleft() # 작은거 빼버림. 
            count+=1

        else: # 누적X
            answer.append(count)
            current_day=q_days.popleft()
            count=1
            
    answer.append(count)
            
    return answer

 

 

 

Skills :

  1. 문제의 해결에 따라, popleft()를 while문 외부 및 내부에서 수행함.
  2. 업데이트 될 때마다 초기화를 else에서 함.