Skip to content

Commit 84c58b8

Browse files
committed
[PGS] 이중우선순위큐 / Level3 / 40분
1 parent cfbda22 commit 84c58b8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import heapq
2+
def solution(operations):
3+
answer = []
4+
heap = []
5+
for o in operations:
6+
command, value = o.split()
7+
if command == "I":
8+
heapq.heappush(heap, int(value))
9+
else:
10+
if heap:
11+
if value == '1':
12+
heap.sort()
13+
heap.pop()
14+
elif value == '-1':
15+
heapq.heappop(heap)
16+
if heap:
17+
answer = [max(heap), min(heap)]
18+
else:
19+
answer = [0, 0]
20+
return answer

0 commit comments

Comments
 (0)