1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import heapq def solution(scoville, K): answer = 0 heapq.heapify(scoville) while True: min1 = heapq.heappop(scoville) if min1 >= K: break elif len(scoville) == 0: answer = -1 break min2 = heapq.heappop(scoville) new_scoville = min1 + 2*min2 heapq.heappush(scoville, new_scoville) answer += 1 return answer # 프로그래머스 - 더 맵게 # https://school.programmers.co.kr/learn/courses/30/lessons/42626 | cs |
'Data Engineering > Python' 카테고리의 다른 글
| [코테] 프로그래머스 - 합승 택시 요금 Python 코드 (0) | 2025.10.16 |
|---|---|
| [코테] 프로그래머스 - 베스트앨범 Python 코드 (0) | 2025.10.15 |
| [코테] 프로그래머스 - 삼각 달팽이 Python 코드 (0) | 2025.10.15 |
| [코테] 프로그래머스 - 시소 짝꿍 Python 코드 (0) | 2025.10.15 |
| [코테] 프로그래머스 - 가장 큰 수 Python 코드 (0) | 2025.09.18 |