분류 전체보기 261

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

출처: 프로그래머스 코딩 테스트 연습, 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 [..

반응형