Skip to content

Commit ba7bb6f

Browse files
committed
[level 3] Title: 이중우선순위큐, Time: 102.62 ms, Memory: 135 MB -BaekjoonHub
1 parent 6af7c70 commit ba7bb6f

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-
메모리: 143 MB, 시간: 117.45 ms
7+
메모리: 135 MB, 시간: 102.62 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2025년 09월 06일 16:57:25
19+
2025년 09월 16일 09:37:13
2020

2121
### 문제 설명
2222

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22

33
class Solution {
44
public int[] solution(String[] operations) {
5-
// 오름차순: 최솟값
6-
PriorityQueue<Integer> ascPq = new PriorityQueue<>();
7-
// 내림차순: 최댓값
8-
PriorityQueue<Integer> descPq = new PriorityQueue<>((a,b) -> b - a);
5+
PriorityQueue<Integer> ascpq = new PriorityQueue<>(); // 오름차순(최솟값)
6+
PriorityQueue<Integer> descpq = new PriorityQueue<>((a,b) -> b - a); // 내림차순(최댓값)
97

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

15-
if(commend.equals("I")){
16-
ascPq.offer(num);
17-
descPq.offer(num);
14+
if(command.equals("I")){
15+
ascpq.offer(num);
16+
descpq.offer(num);
1817
size ++;
19-
} else{
18+
} else {
2019
if(size > 0) {
21-
if(num == -1) { // 최솟값 삭제
22-
descPq.remove(ascPq.poll());
20+
if(num == -1) { // 최솟값 삭제
21+
descpq.remove(ascpq.poll());
2322
size --;
24-
} else { // 최댓값 삭제
25-
ascPq.remove(descPq.poll());
23+
} else {
24+
ascpq.remove(descpq.poll());
2625
size --;
2726
}
2827
}
2928
}
3029
}
31-
if(size > 0){
32-
return new int[] {descPq.poll(),ascPq.poll()};
33-
} else{
30+
31+
if(size == 0) {
3432
return new int[] {0,0};
3533
}
34+
35+
return new int[] {descpq.poll(), ascpq.poll()};
3636
}
3737
}

0 commit comments

Comments
 (0)