Skip to content

Commit a82fa4f

Browse files
committed
[level 3] Title: 이중우선순위큐, Time: 119.04 ms, Memory: 138 MB -BaekjoonHub
1 parent 9f51a71 commit a82fa4f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
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-
메모리: 123 MB, 시간: 94.37 ms
7+
메모리: 138 MB, 시간: 119.04 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2025년 08월 30일 12:37:19
19+
2025년 09월 02일 17:37:10
2020

2121
### 문제 설명
2222

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import java.util.*;
22
class Solution {
33
public int[] solution(String[] operations) {
4-
// 오름차순 우선순위 큐
5-
PriorityQueue<Integer> ascPq = new PriorityQueue<>();
6-
// 내림차순 우선순위 큐
7-
PriorityQueue<Integer> descPq = new PriorityQueue<>((a,b) -> b-a);
4+
PriorityQueue<Integer> apq = new PriorityQueue<>(); // 오름차순
5+
PriorityQueue<Integer> dpq = new PriorityQueue<>((a,b) -> b - a); // 내림차순
86

97
int size = 0;
10-
for(String operation: operations){
11-
String[] params = operation.split(" ");
12-
String command = params[0]; // 명령어
13-
String number = params[1]; // 숫자
14-
if(command.equals("I")){ // 삽입 명령어
15-
ascPq.offer(Integer.parseInt(number));
16-
descPq.offer(Integer.parseInt(number));
8+
9+
for(String operation : operations){
10+
String command = operation.split(" ")[0];
11+
String numStr = operation.split(" ")[1];
12+
13+
if(command.equals("I")){
14+
int num = Integer.parseInt(numStr);
15+
apq.offer(num);
16+
dpq.offer(num);
1717
size ++;
18-
} else { // 삭제 명령어
18+
} else{
1919
if(size > 0){
20-
if(number.equals("-1")) { // 최솟값 삭제
21-
descPq.remove(ascPq.poll());
20+
if(numStr.equals("-1")) { // 최솟값 삭제
2221
size --;
23-
} else { // 최댓값 삭제
24-
ascPq.remove(descPq.poll());
22+
dpq.remove(apq.poll());
23+
} else { // 최댓값 삭제
2524
size --;
25+
apq.remove(dpq.poll());
2626
}
2727
}
2828
}
2929
}
30-
if(size == 0) return new int[]{0,0};
31-
return new int[]{descPq.poll(),ascPq.poll()};
30+
if(size == 0) return new int[] {0,0};
31+
return new int[] {dpq.poll(), apq.poll()};
3232
}
3333
}

0 commit comments

Comments
 (0)