๐ŸคRyusun๐Ÿค 2022. 11. 16. 21:29

์šฐ์„ ์ˆœ์œ„ ํ ๋ฌธ์ œ

 

๋ฌธ์ œ : https://school.programmers.co.kr/learn/courses/30/lessons/42626

 

import heapq
def solution(scoville, K):
    heapq.heapify(scoville)
    answer= 0
    while scoville[0] < K:
        a = heapq.heappop(scoville) + (heapq.heappop(scoville)*2)
        heapq.heappush(scoville, a)
        answer += 1
        if len(scoville) <2 and scoville[0] < K:
            return -1
    return answer

 

heappop์€ ๊ฐ€์žฅ ์ž‘์€ ์›์†Œ๋ฅผ ์ฐพ์•„์„œ ๋ฐ˜ํ™˜ํ›„ ์‚ญ์ œ๋œ๋‹ค.