최대 1 분 소요

Python

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

댓글남기기