파이썬으로 부시자! Python with Coreenee

프로그래머스 - Heap - 이중우선순위큐

문제

스크린샷 2020-04-17 오후 3 18 24

입력

스크린샷 2020-04-17 오후 3 18 31


나의 처음 코드

음,,, 이 문제는 왜 우선순위지,,,? 내가 그렇게 안 푼건가,,,? 흠흠,,,, 난 이렇게 풀었다,,, 딱히 설명할 길이 없다. 리스트에서 append, pop한게 끝이기 때문에,,, ㅎㅎ

def solution(operations):
arr = []
for operation in operations:
    op_arr = operation.split(' ')
    operation = op_arr[0]
    value = int(op_arr[1])
    
    if operation == 'I':
        arr.append(value)
    else:
        if value == -1:
            if len(arr) > 0:
                arr.pop(arr.index(min(arr)))
        else:
            if len(arr) > 0:
                arr.pop(arr.index(max(arr)))

if len(arr) > 0:
    return [max(arr), min(arr)]
else:
    return [0,0]

why priority heap?