문제풀이/프로그래머스

[프로그래머스][Lv2] - 더 맵게 (Python)

얄루몬 2021. 10. 15. 12:52

import heapq
def solution(scoville, K):
    answer = 0
    heapq.heapify(scoville)
    
    while scoville[0] < K:
        hap = heapq.heappop(scoville) + (heapq.heappop(scoville)*2)
        heapq.heappush(scoville,hap)
        answer += 1
        
        if len(scoville) == 1 and scoville[0] < K:
            return -1

    return answer