Programmers - 더 맵게 [파이썬] 본문
728x90
출처:
https://programmers.co.kr/learn/courses/30/lessons/42626
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
import heapq
def solution(scoville, K):
answer = 0
heap = []
for num in scoville:
heapq.heappush(heap, num)
while heap[0] < K:
try:
heapq.heappush(heap,heapq.heappop(heap) + (heapq.heappop(heap)*2))
except IndexError:
return -1
answer += 1
return answer
'Algorithms > Heap' 카테고리의 다른 글
Programmers - 이중우선순위큐 [파이썬] (0) | 2020.05.13 |
---|---|
Programmers - 디스크 컨트롤러 [파이썬] (0) | 2020.05.13 |
Programmers - 라면공장 [파이썬] (0) | 2020.05.13 |
파이썬 heapq 모듈 사용법 (0) | 2020.05.13 |
Comments