You are viewing a single comment's thread. Return to all comments →
Slightly simplified version:
static Scanner in = new Scanner( System.in ); static Deque<Integer> stack = new ArrayDeque(); static Integer max = Integer.MIN_VALUE; public static void main(String[] args) { int numQueries = in.nextInt(); for ( int i=0; i<numQueries; i++ ) switch( in.nextInt() ) { case 1: int n = in.nextInt(); max = Math.max( n, max ); stack.push( max ); break; case 2: stack.pollFirst(); if ( stack.isEmpty() ) max = Integer.MIN_VALUE; else max = stack.peek(); break; case 3: System.out.println( max ); break; } } }
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 →
Slightly simplified version: