You are viewing a single comment's thread. Return to all comments →
public static List<Integer> getMax(List<String> operations) { Stack<Integer> queue = new Stack<Integer>(); List<Integer> result = new ArrayList<Integer>(); PriorityQueue<Integer> sortedNumbers = new PriorityQueue<Integer>(Collections.reverseOrder()); for (String operation: operations) { String[] partes = operation.split(" "); if ("1".equals(partes[0])) { queue.push(Integer.parseInt(partes[1])); sortedNumbers.add(Integer.parseInt(partes[1])); } if ("2".equals(partes[0])) { Integer removido = queue.pop(); sortedNumbers.remove(removido); } if ("3".equals(partes[0])) { result.add(sortedNumbers.peek()); } } return result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Maximum Element
You are viewing a single comment's thread. Return to all comments →