Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 구현
- N과M
- 그리디
- BOJ
- 프로그래머스
- BFS
- 재귀
- 가상메모리 관리
- 수학
- dfs
- level2
- 코딩테스트
- level3
- 힙
- 파이썬
- python
- DP
- 운영체제
- level0
- 브루트포스
- 가상메모리
- level1
- 딕셔너리
- 스택
- dict
- programmers
- 다익스트라
- 다이나믹 프로그래밍
- MYSQL
- 백준
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [더 맵게] 파이썬 본문
https://programmers.co.kr/learn/courses/30/lessons/42626
#프로그래머스 더 맵게
def solution(scoville, K):
import heapq
answer = 0
heapq.heapify(scoville)
leng=len(scoville)
while scoville[0]<K and leng>1:
x1=heapq.heappop(scoville)
x2=heapq.heappop(scoville)
new= x1+x2*2
heapq.heappush(scoville,new)
leng-=1
answer+=1
if scoville[0]>=K:
return answer
else:
return -1
파이썬 heapq 내장함수를 이용하여 해결하였다.
*알게된사실: (걸리는 시간 pop()>heappop()이다.)
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [튜플] 파이썬 (0) | 2021.12.17 |
---|---|
프로그래머스 level2 [전화번호 목록] 파이썬 (0) | 2021.12.11 |
프로그래머스 level2 [오픈채팅방] 파이썬 (0) | 2021.12.10 |
프로그래머스 level2 [위장] 파이썬 (0) | 2021.12.10 |
프로그래머스 level2 [카펫] 파이썬 (0) | 2021.12.10 |