You are viewing a single comment's thread. Return to all comments →
Java O(Q log n)
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Q = scanner.nextInt(); PriorityQueue<Integer> heap = new PriorityQueue<>(); for (int i = 0; i < Q; i++) { int queryType = scanner.nextInt(); switch (queryType) { case 1: int elementToAdd = scanner.nextInt(); heap.add(elementToAdd); break; case 2: int elementToDelete = scanner.nextInt(); heap.remove(elementToDelete); break; case 3: System.out.println(heap.peek()); break; } } scanner.close(); }
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 →
Java O(Q log n)