상세 컨텐츠

본문 제목

[프로그래머스 코딩테스트 고득점 kit] 더 맵게 python

카테고리 없음

by yukmim 2022. 1. 23. 17:18

본문

import heapq

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

if len(scoville) > 1:

    num 1 = heapq.heappop(scoville) ...

else:

    return -1

 

을 하면 런타임 오류가 난다... 이유는 i dont know... why..

댓글 영역