You are viewing a single comment's thread. Return to all comments →
public static List<Integer> getMax(List<String> operations) { List<Integer> max = new ArrayList<>(); Deque<Integer> stack = new ArrayDeque<>(); operations.stream().forEach(op -> { if(op.contains("1")) { String temp = op.split(" ")[1]; stack.offerFirst(Integer.parseInt(temp)); } else if(op.contains("2")) { stack.pollFirst(); } else if(op.contains("3")) { Integer temp = stack.stream().mapToInt(i -> i).max().getAsInt(); max.add(temp); } }); return max; }
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 →