import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while scoville[0] < K:
a = heapq.heappop(scoville) + (heapq.heappop(scoville) * 2)
heapq.heappush(scoville, a)
answer += 1
if len(scoville) == 1 and scoville[0] < K:
return -1
return answer
'Language > Python' 카테고리의 다른 글
[Python / 프로그래머스 level 2] 위장 (0) | 2021.08.16 |
---|---|
[Python / 프로그래머스 level 2] 기능개발 (0) | 2021.08.13 |
[Python / 프로그래머스 level 2] 다음 큰 숫자 (0) | 2021.08.10 |
[Python / 프로그래머스 level 2] 카펫 (0) | 2021.08.10 |
[Python / 프로그래머스 level 2] 주식가격 (0) | 2021.08.09 |