heap 한번 풀어보자.
[Python3] 우선순위 큐 & Heap
[Python3] heapq 사용법
import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while scoville[0] < K:
if len(scoville) == 1: return -1
num1,num2 = heapq.heappop(scoville),heapq.heappop(scoville)
heapq.heappush(scoville,num1 + num2 *2)
answer+=1
return answer