classMaxQueue{//使用双向队列原因:维护递减列表需要元素队首弹出、队尾插入、队尾弹出操作皆为 O(1) 时间复杂度。Queue<Integer> queue;Deque<Integer> queue2;publicMaxQueue(){
queue=newLinkedList<>();
queue2=newLinkedList<>();}publicintmax_value(){return queue2.isEmpty()?-1:queue2.peekFirst();}publicvoidpush_back(int value){
queue.offer(value);while(!queue2.isEmpty()&&queue2.peekLast()<value){
queue2.pollLast();}
queue2.offerLast(value);}publicintpop_front(){if(queue.isEmpty())return-1;if(!queue2.isEmpty()&&queue.peek().equals(queue2.peekFirst())){
queue2.pollFirst();}return queue.poll();}}/**
* Your MaxQueue object will be instantiated and called as such:
* MaxQueue obj = new MaxQueue();
* int param_1 = obj.max_value();
* obj.push_back(value);
* int param_3 = obj.pop_front();
*/