Skip to content

Commit fe518ac

Browse files
committed
[level 3] Title: 이중우선순위큐, Time: 117.45 ms, Memory: 143 MB -BaekjoonHub
1 parent 034b068 commit fe518ac

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

프로그래머스/3/42628. 이중우선순위큐/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 138 MB, 시간: 119.04 ms
7+
메모리: 143 MB, 시간: 117.45 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 09월 02일 17:37:10
19+
2025년 09월 06일 16:57:25
2020

2121
### 문제 설명
2222

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
import java.util.*;
2+
23
class Solution {
34
public int[] solution(String[] operations) {
4-
PriorityQueue<Integer> apq = new PriorityQueue<>(); // 오름차순
5-
PriorityQueue<Integer> dpq = new PriorityQueue<>((a,b) -> b - a); // 내림차순
5+
// 오름차순: 최솟값
6+
PriorityQueue<Integer> ascPq = new PriorityQueue<>();
7+
// 내림차순: 최댓값
8+
PriorityQueue<Integer> descPq = new PriorityQueue<>((a,b) -> b - a);
69

710
int size = 0;
8-
911
for(String operation : operations){
10-
String command = operation.split(" ")[0];
11-
String numStr = operation.split(" ")[1];
12+
String commend = operation.split(" ")[0];
13+
int num = Integer.parseInt(operation.split(" ")[1]);
1214

13-
if(command.equals("I")){
14-
int num = Integer.parseInt(numStr);
15-
apq.offer(num);
16-
dpq.offer(num);
15+
if(commend.equals("I")){
16+
ascPq.offer(num);
17+
descPq.offer(num);
1718
size ++;
1819
} else{
19-
if(size > 0){
20-
if(numStr.equals("-1")) { // 최솟값 삭제
20+
if(size > 0) {
21+
if(num == -1) { // 최솟값 삭제
22+
descPq.remove(ascPq.poll());
2123
size --;
22-
dpq.remove(apq.poll());
23-
} else { // 최댓값 삭제
24+
} else { // 최댓값 삭제
25+
ascPq.remove(descPq.poll());
2426
size --;
25-
apq.remove(dpq.poll());
2627
}
2728
}
2829
}
2930
}
30-
if(size == 0) return new int[] {0,0};
31-
return new int[] {dpq.poll(), apq.poll()};
31+
if(size > 0){
32+
return new int[] {descPq.poll(),ascPq.poll()};
33+
} else{
34+
return new int[] {0,0};
35+
}
3236
}
3337
}

0 commit comments

Comments
 (0)