import java.io.*;
import java.util.*;
class Solution {
public int[] solution(String[] operations) {
PriorityQueue<Integer>minpq=new PriorityQueue<>();
PriorityQueue<Integer>maxpq=new PriorityQueue<>(Collections.reverseOrder());
int n=0;
for(String operation:operations){
if(operation.startsWith("I ")){
n=Integer.parseInt(operation.substring(2));
minpq.offer(n);
maxpq.offer(n);
}
else if(!minpq.isEmpty() && operation.equals("D -1")){
maxpq.remove(minpq.poll());
}else if(!maxpq.isEmpty() && operation.equals("D 1")){
minpq.remove(maxpq.poll());
}
}
if(minpq.isEmpty() && maxpq.isEmpty()){
return new int[]{0,0};
}
return new int[]{maxpq.poll(),minpq.poll()};
}
}
문제 자체는 어렵지 않다 개인적으로 Collections.reverseOrder() 내림차순과
startsWith 랑 케이스를 잘 나누면 쉽게 풀 수 있는 문제로 보인다.
'프로그래머스 백준 문제' 카테고리의 다른 글
| 디스크 컨트롤러 (0) | 2026.09.12 |
|---|---|
| 전화번호 목록 (0) | 2026.07.24 |
| 프로그래머스 Hash 문제 (이거는 보자) (0) | 2026.07.22 |
| 프로그래머스 HashMap 기본문제 (0) | 2026.07.22 |
| 코테 Scanner 객체 사용법 (0) | 2026.07.21 |