이중 우선순위 큐 (for JAVA)
import java.util.*;
class Solution {
public int[] solution(String[] operations) {
int[] answer;
PriorityQueue<Integer> data = new PriorityQueue<>(); // 순차정렬
PriorityQueue<Integer> data1 = new PriorityQueue<>(Collections.reverseOrder()); // 역정렬
for (int i = 0;i< operations.length;i++) {
if (operations[i].contains("I")) {
String[] oper = operations[i].split(" ");
data.add(Integer.parseInt(oper[1]));
data1.add(Integer.parseInt(oper[1]));
}
if (data.isEmpty()) {
continue;
}
if (operations[i].equals("D 1")) { // 최대값 삭제
int max = data1.peek();
data.remove(max);
data1.remove(max);
} else if (operations[i].equals("D -1")){ // 최소값 삭제
int min = data.peek();
data.remove(min);
data1.remove(min);
}
}
if (data.size() == 0) {
answer = new int[]{0,0};
} else {
answer = new int[2];
answer[0] = data1.peek();
answer[1] = data.peek();
}
return answer;
}
}
설명은 나중에 너무 졸려서 20000
Author And Source
이 문제에 관하여(이중 우선순위 큐 (for JAVA)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ksy9107/이중-우선순위-큐-for-JAVA저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)