본문 바로가기
알고리즘/소스코드

PROGRAMMERS 42628: 이중우선순위큐

by cjw.git 2021. 3. 24.

Link : programmers.co.kr/learn/courses/30/lessons/42628


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import heapq
 
 
def solution(operations):
    heap = []
    for i in operations:
        opcode, operand = i.split(' ')
        if opcode == "I":
            heapq.heappush(heap, int(operand))
        elif opcode == "D":
            if len(heap) > 0:
                if operand == "1":
                    heap.pop()
                else:
                    heapq.heappop(heap)
    return [max(heap), min(heap)] if len(heap) > 0 else [00]
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

댓글