목록이중우선순위큐 (1)
컴공생의 다이어리

[프로그래머스] 이중우선순위큐 - 파이썬(Python) import heapq def solution(operations): heap = [] for op in operations: print(op) command, num = op.split() if command == 'D': if not heap: # 삭제할 데이터가 없다면 continue if num == '1': # 최댓값 삭제 heap.remove(heapq.nlargest(1, heap)[0]) else: # 최솟값 삭제 heapq.heappop(heap) else: heapq.heappush(heap, int(num)) return [heapq.nlargest(1, heap)[0], heap[0]] if heap else [0, 0] htt..
Development/Algorithm & Coding Test
2022. 7. 28. 00:01