프로그래머스/level 3

[프로그래머스] 이중우선순위큐

binaryJournalist 2022. 6. 23. 21:04
반응형

 

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

 

 

 

import heapq
def solution(operations):
    answer = []
    while operations:
        o, num = operations.pop(0).split()
        if o == "I":
            heapq.heappush(answer, int(num))
        elif answer and o == "D" and int(num) > 0:
            answer.pop()
        elif answer and o == "D" and int(num) < 0:
            answer.pop(0)
        answer.sort()
    if answer:
        return [answer[-1], answer[0]]
    else:
        return [0,0]

 

 

반응형