• + 1 comment

    By looking at some comment, it seems like no one actually tried to use priority queue to mimic the min heap? So many ppl used treeset but I am not sure which one is actually the right one to use. After checking this StackOverflow, I decided to use priority queue http://stackoverflow.com/questions/14165325/is-there-a-heap-in-java Also, I don't want to bother implementing heap from the scratch...

    public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            PriorityQueue<Integer> minHeap = new PriorityQueue<Integer>(n, (i1, i2) -> i1.compareTo(i2));
            /*
            PriorityQueue<Integer> minHeap = new PriorityQueue<Integer>(n, new Comparator<Integer>(
                                                                            int compare(Integer i1, Integer i2){
                                                                               return i1.compareTo(i2);
                                                                            }));
            */
            for(int i=0; i<n; i++){
                int type = scan.nextInt();
                switch(type){
                    case 1:
                        int data1 = scan.nextInt();
                        minHeap.offer(data1);
                    break;
                    case 2:
                        int data2 = scan.nextInt();
                        minHeap.remove(data2);
                    break;
                    case 3:
                        System.out.println(minHeap.peek());
                    break;
                    default:
                    break;
                }
            }
        }