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