๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/42626
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 2๋จ๊ณ - ๋ ๋งต๊ฒ
import heapq
def solution(scoville, k):
answer = 0
heapq.heapify(scoville)
while scoville[0] < k:
heapq.heappush(scoville, heapq.heappop(scoville) + heapq.heappop(scoville) * 2)
answer += 1
if len(scoville) == 1 and scoville[0] < k:
return -1
return answer
print(solution([1, 2, 3, 9, 10, 12], 7))
ํ ์๋ฃ๊ตฌ์กฐ๋ฅผ ์ฌ์ฉํด ํด๊ฒฐํ์๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (1) | 2023.05.10 |
---|---|
โฌ [Programmers] [Python] [Level2] ์นด๋ ๋ญ์น (0) | 2023.04.17 |
โฌ [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] n์ง์ ๊ฒ์ (0) | 2023.04.17 |
โฌ [Programmers] [Python] [2018 KAKAO BLIND RECRUITMENT] [Level2] [3์ฐจ] ์์ถ (0) | 2023.04.14 |
โฌ [Programmers] [Python] [Level1] ์ถ์ต ์ ์ (0) | 2023.04.13 |