파이썬 내장 함수인 heapq 를 사용하여 동일하게 돌렸더니 되었다.
파이썬의 heapq와 heap에 대해 공부를 해서 작성해야지
import heapq
def solution(scoville, K):
answer = 0
heapq.heapify(scoville)
while scoville[0] < K and len(scoville) != 1 :
answer += 1
rank = heapq.heappop(scoville) + heapq.heappop(scoville) * 2
heapq.heappush(scoville,rank)
if len(scoville) == 1 and scoville[0] < K:
return -1
return answer
프로그래머스 주식가격 파이썬 (0) | 2021.03.25 |
---|---|
프로그래머스 모의고사 파이썬 (0) | 2021.03.23 |
프로그래머스 더 맵게 파이썬 (0) | 2021.03.23 |
다리를 지나는 트럭 파이썬 (0) | 2021.03.23 |
프로그래머스 전화번호 목록 python (0) | 2021.03.17 |
댓글 영역