单调栈
import java.util.Stack;
public class Solution {
// 最小 栈, 两个栈
Stack<Integer> st = new Stack<>();
Stack<Integer> smin = new Stack<>();
public void push(int node) {
st.push(node);
if (smin.isEmpty()) smin.push(Integer.MAX_VALUE);
smin.push(Math.min(smin.peek(), node));
}
public void pop() {
st.pop();
smin.pop();
}
public int top() {
return st.peek();
}
public int min() {
return smin.peek();
}
}

京公网安备 11010502036488号