from heapq import heappush, heappop, nlargest
def solution(operations):
answer = []
for operation in operations:
standard, queue = operation.split(' ')
if standard == 'I':
heappush(answer, int(queue))
else:
if len(answer) == 0:
pass
elif len(answer) == 1:
heappop(answer)
else:
if queue == '-1':
heappop(answer)
else:
temp = []
count = len(answer)
for i in range(count-1):
heappush(temp, heappop(answer))
answer = temp
if len(answer) == 0:
return [0, 0]
else:
answer = [max(answer), min(answer)]
return answer
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[파이썬][프로그래머스] 정렬 H-Index (0) | 2022.11.23 |
---|---|
[파이썬][프로그래머스] 정렬 K번째수 (0) | 2022.11.22 |
[파이썬][프로그래머스] Lv. 1 폰켓몬 (0) | 2022.10.02 |
[파이썬][프로그래머스] Lv. 1 완주하지 못한 선수 (0) | 2022.10.02 |
[파이썬][프로그래머스] Lv. 2 k진수에서 소수 개수 구하기 (0) | 2022.09.06 |
댓글