import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while scoville[0] < K:
hap = heapq.heappop(scoville) + (heapq.heappop(scoville)*2)
heapq.heappush(scoville,hap)
answer += 1
if len(scoville) == 1 and scoville[0] < K:
return -1
return answer
'문제풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스][Lv1] - 음양 더하기(Python) (0) | 2021.10.17 |
---|---|
[프로그래머스][Lv1] - 없는 숫자 더하기 (Python) (0) | 2021.10.17 |
[프로그래머스][Lv1] - [1차] 비밀지도 (Python) (0) | 2021.10.15 |
[프로그래머스][Lv1] - 부족한 금액 계산하기(Python) (0) | 2021.10.14 |
[프로그래머스][Lv1] - k번째 수 (Python) (0) | 2021.10.14 |