코딩테스트/자료구조(스택,큐,해시,힙)

[스택] (프로그래머스_42586) 기능개발 - 파이썬

영최 2024. 9. 5. 14:41
728x90

✅ 스택 사용

from math import ceil
def solution(progresses, speeds):
    stack = []
    answer = []
    cnt = 0
    for p,s in zip(progresses,speeds):
        cost = ceil((100-p)/s)
        if stack:
            if stack[-1]>=cost:
                answer[cnt]+=1
            else:
                stack.pop()
                cnt+=1
                answer.append(1)
                stack.append(cost)
        else:
            answer.append(1)
            stack.append(cost)
            
    
    return answer
728x90