You are viewing a single comment's thread. Return to all comments →
import java.io.*; import java.util.*; public class Solution { static PriorityQueue<Integer> minHeap = new PriorityQueue<>(); public static void insert(int data){ minHeap.add(data); } public static void delete(int data){ minHeap.remove(data); } public static void printMin(){ System.out.println(minHeap.peek()); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0;i<n;i++){ int action = sc.nextInt(); if(action == 1){ int data = sc.nextInt(); insert(data); } else if(action == 2){ int data = sc.nextInt(); delete(data); } else if(action == 3){ printMin(); } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
QHEAP1
You are viewing a single comment's thread. Return to all comments →