File tree Expand file tree Collapse file tree 2 files changed +20
-20
lines changed
Expand file tree Collapse file tree 2 files changed +20
-20
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 143 MB, 시간: 117.45 ms
7+ 메모리: 135 MB, 시간: 102.62 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 09월 06일 16:57:25
19+ 2025년 09월 16일 09:37:13
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 22
33class 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}
You can’t perform that action at this time.
0 commit comments