8000 [23-02-01] hyuksoon.py by chs98412 · Pull Request #40 · da-in/algorithm-study · GitHub
[go: up one dir, main page]

Skip to content

[23-02-01] hyuksoon.py #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Create [힙] 더 맵게 hyuksoon.py
  • Loading branch information
chs98412 committed Jan 31, 2023
commit 5bbeb300332d93f4ebcb2a9b0bc543e2d54314da
19 changes: 19 additions & 0 deletions Programmers - 고득점 Kit/[힙] 더 맵게/hyuksoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import heapq

def solution(scoville, K):
answer = 0
heapq.heapify(scoville)

while scoville and scoville[0] < K:
try:
result1 = heapq.heappop(scoville)
result2 = heapq.heappop(scoville)
heapq.heappush(scoville, result1+(2*result2))
answer += 1
except:
heapq.heappush(scoville, result1)
break
if scoville[0] >= K:
return answer
else:
return -1
0