单调队列
https://labuladong.github.io/algo/2/20/51/
class MonotonicQueue
{
private LinkedList<Integer> queue = new LinkedList<Integer>();
public MonotonicQueue()
{
queue = new LinkedList<Integer>();
}
public void push(int x)
{
while(!queue.isEmpty() && queue.getLast() < x)
{
queue.pollLast();
}
queue.addLast(x);
}
public int max()
{
return queue.getFirst();
}
public void pop(int x)
{
if( x == queue.getFirst())
{
queue.pollFirst();
}
}
}Last updated