[프로그래머스] 더 맵게
효율성을 위해 heapq를 사용해야했다. heap은, 부모노드가 무조건 자식노드보다 크거나 같은 값을 갖는 완전이진트리이다. 주요 함수로는, heapq.heappush(heap, i) heapq.heappop(heap) heapq.heapify(heap) 이렇게 세 가지가 있다. import heapq def solution(scoville, K): answer = 0 heap = [] for i in scoville: heapq.heappush(heap, i) while heap[0] < K: if len(heap) == 1: return -1 new = heapq.heappop(heap) + heapq.heappop(heap) * 2 heapq.heappush(heap, new) answer = an..
코딩테스트 대비
2022. 2. 20. 14:46
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- LGSVL
- matplotlib
- 파이썬
- tensorflow
- torch
- dfs
- 동적프로그래밍
- 이것이코딩테스트다
- 최소신장트리
- n과m
- 카카오
- Python
- 설치하기
- 다익스트라
- notfound
- shellscript
- 프로그래머스
- CUDA
- PIP
- error
- 백준
- docker
- torchscript
- BFS
- 백트래킹
- numpy
- 설치
- version
- 코딩테스트
- pytorch
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함