[Level 2] 더 맵게

나며기·2021년 9월 27일
0

programmers

목록 보기
61/111
post-thumbnail
import heapq

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

0개의 댓글