728x90

나의 풀이
import heapq
def solution(operations):
heap = []
while operations:
cmd, num = operations.pop(0).split(' ')
if cmd == 'I':
heapq.heappush(heap, int(num))
elif heap:
if num == '1':
heap = heapq.nsmallest(len(heap) - 1, heap)
heapq.heapify(heap)
elif num == '-1':
heapq.heappop(heap)
if heap:
return [heapq.nlargest(1, heap)[0], heap[0]]
else:
return [0, 0]
반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] 가장 큰 수 (0) | 2022.06.03 |
|---|---|
| [프로그래머스/파이썬] K번째수 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 디스크 컨트롤러 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 더 맵게 (0) | 2022.06.03 |
| [프로그래머스/파이썬] 주식가격 (0) | 2022.06.03 |