public class Solution {
// 1 2 3 4 -1
Stack<integer> stackAll = new Stack<>();
// 1 1 1 1 -1
Stack<integer> min = new Stack<>();</integer></integer>
public void push(int node) {
if(!stackAll.isEmpty() && node > min.peek()){
node = min.peek();
}
stackAll.push(node);
min.push(node);
}
public void pop() {
stackAll.pop();
min.pop();
}
public int top() {
return stackAll.peek();
}
public int min() {
return min.peek();
}}

京公网安备 11010502036488号