heapify를 잘 못 쓸 때
heap = heapq.heapify(scoville)
기본 형식
heapq.heapify(scoville)
print(scoville)
import heapq
def solution(scoville, K):
heapq.heapify(scoville)
answer = 0
while scoville[0] < K:
try:
num = heapq.heappop(scoville) + heapq.heappop(scoville)*2
heapq.heappush(scoville, num)
answer += 1
except IndexError:
return -1
return answer