문제
- 프로그래머스 코딩테스트 연습 - 힙(Heap) - 더 맵게
- 문제링크
풀이
import heapq
def solution(scoville, K):
num_foolds = len(scoville)
heapq.heapify(scoville)
score = heapq.heappop(scoville)
iter = 0
while iter < num_foolds - 1 and score < K:
heapq.heappush(scoville, score + heapq.heappop(scoville) * 2)
score = heapq.heappop(scoville)
iter += 1
return -1 if (iter == num_foolds - 1 and score < K) else iter