총 76.2/100
import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while len(hq)>1:
a = heapq.heappop(scoville)
b = heapq.heappop(scoville)
if(b < K) :
k = a + (b*2)
heapq.heappush(scoville, k)
answer +=1
else :
return answer
return -1
총 100/100
import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
a = heapq.heappop(scoville)
while len(scoville) > 0:
b = heapq.heappop(scoville)
a = heapq.heappushpop(scoville, a + b + b)
if a >= K:
return answer + 1
answer += 1
return -1
import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while hq[0]<K:
try :
heapq.heappush(hq,heapq.heappop(scoville) + (heapq.heappop(scoville) * 2))
answer +=1
except IndexError:
return -1
return answer