(프로그래머스) 더 맵게

hwisaac·2024년 11월 21일
0

코테TIL

목록 보기
16/20

문제링크

https://school.programmers.co.kr/learn/courses/30/lessons/42626

풀이

import heapq

def solution(scoville, K):
    heapq.heapify(scoville)
    
    count = 0
    while scoville[0] < K:
        if len(scoville) < 2:
            return -1
        
        first = heapq.heappop(scoville)
        second = heapq.heappop(scoville)
        
        new_food = first + (second * 2)
        heapq.heappush(scoville, new_food)
        
        count += 1
    
    return count

0개의 댓글