Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 항해플러스
- axios
- programmers
- json-server
- Algorithm
- 자바
- 리액트
- java
- react-redux
- createSlice
- react
- 이코테
- react-router
- 테코테코
- 코딩테스트합격자되기
- redux-toolkit
- Get
- 알고리즘
- Python
- redux
- maeil-mail
- redux-saga
- 프로그래머스
- 항해99
- JavaScript
- C++
- sw expert academy
- useDispatch
- 매일메일
- SW
Archives
- Today
- Total
Binary Journey
[프로그래머스] 이중우선순위큐 본문
반응형
출처: 프로그래머스 코딩 테스트 연습, 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]
반응형
'프로그래머스 > level 3' 카테고리의 다른 글
[프로그래머스] 베스트 앨범 (0) | 2022.05.20 |
---|---|
[프로그래머스] 순위 (0) | 2022.04.21 |
[프로그래머스] 가장 먼 노드 (0) | 2022.04.21 |
[프로그래머스] 정수 삼각형 (0) | 2022.03.16 |
[프로그래머스] 헤비 유저가 소유한 장소 (MySQL) (0) | 2021.08.10 |