File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .*;
2+ import java .io .*;
3+
4+
5+ class Solution {
6+ PriorityQueue <Integer > minh = new PriorityQueue <>();
7+ PriorityQueue <Integer > maxh = new PriorityQueue <>();
8+ public int [] solution (String [] operations ) {
9+ StringTokenizer st ;
10+ int [] answer = {0 ,0 };
11+ for (String operation : operations ) {
12+ st = new StringTokenizer (operation );
13+ String order = st .nextToken ();
14+ int num = Integer .parseInt (st .nextToken ());
15+
16+ if (order .equals ("I" )) {
17+ minh .offer (num );
18+ maxh .offer (-num );
19+ continue ;
20+ }
21+ else {
22+ if (num ==1 ) {
23+ if (maxh .size ()==0 ) continue ;
24+ else {
25+ minh .remove (-maxh .poll ());
26+
27+ }
28+ }
29+ else {
30+ if (minh .size ()==0 ) continue ;
31+ else {
32+ maxh .remove (minh .poll ());
33+ }
34+ }
35+ }
36+ }
37+ if (minh .size ()>0 ) {
38+ return new int [] {-maxh .peek (),minh .peek ()};
39+ }
40+ return answer ;
41+ }
42+ }
43+
44+ public class Main {
45+ public static void main (String [] args ){
46+ String [] operations = {"I 16" ,"D 1" };
47+ System .out .println (new Solution ().solution (operations ));
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments