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 | 31 |
Tags
- BatchNormalization
- clibration
- 자료구조끝판왕문제
- autograd
- 네이버AI부스트캠프
- labelsmoothingloss
- f1loss
- labelsmoothing
- 중복순열
- 우선순위큐
- pytorch
- layernormalization
- 네이버 ai 부스트캠프
- focalloss
- 힙
- noiserobustness
- cmp_to_key
- Focal Loss
- l2penalty
- 밑바닥부터 시작하는 딥러닝
- DataAugmentation
- ImageClassification
- objectdetection
- 프로그래머스
- inference
- Optimizer
- fasterRCNN
- mmdetectionv3
- ComputerVision
- 정렬
Archives
- Today
- Total
HealthyAI
Programmers) level3. 이중우선순위 큐 본문
반응형
max_heap과 min_heap을 동시에 저장 하면서 비교 해야 됐던 이중 우선 순위 큐 문제이다.
처음에는 최댓값을 구하는 함수로 풀었었는데 연산 횟수가 늘고, 자료가 증가 할 수록 연산의 과부화가 생겨 우선순위 큐를 선택하여 다시 풀이법을 공부하였다.
from heapq import heappush, heappop
def solution(operations):
min_heap = []
max_heap = []
for op in operations:
if op == 'D 1':
if max_heap:
heappop(max_heap)
if not max_heap or -max_heap[0] < min_heap[0]:
min_heap, max_heap = [], []
elif op == 'D -1':
if min_heap:
heappop(min_heap)
if not min_heap or -max_heap[0] < min_heap[0]:
min_heap, max_heap = [], []
else:
num = int(op[2:])
heappush(min_heap, num)
heappush(max_heap, -num)
if not min_heap:
return [0,0]
return [-heappop(max_heap), heappop(min_heap)]
반응형
'Coding test > 프로그래머스' 카테고리의 다른 글
Programmers) level2. H-INDEX (0) | 2023.01.19 |
---|---|
Programmers) level2. 가장 큰수 (0) | 2023.01.19 |
Programmers) level3. 베스트앨범 (0) | 2023.01.19 |
Programmers) level2. 위장 (0) | 2023.01.19 |
Programmers) level2. 전화번호 목록 (0) | 2023.01.19 |