본문 바로가기
프로그래머스/lv.2

더 맵게

by bingual 2024. 2. 16.
반응형

 

https://school.programmers.co.kr/learn/courses/30/lessons/42626

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제풀이

import heapq


def solution(scoville, K):
    answer = 0

    heapq.heapify(scoville)
    while len(scoville) > 1 and scoville[0] < K:
        min1 = heapq.heappop(scoville)
        min2 = heapq.heappop(scoville)
        cal = min1 + min2 * 2
        heapq.heappush(scoville, cal)
        answer += 1

    return -1 if scoville[0] < K else answer

'프로그래머스 > lv.2' 카테고리의 다른 글

주차 요금 계산  (0) 2024.02.16
뒤에 있는 큰 수 찾기  (1) 2024.02.16
압축  (0) 2024.02.16
[3차] n진수 게임  (0) 2024.02.15
k진수에서 소수 개수 구하기  (0) 2024.02.09