解
包含min函数的栈
http://www.nowcoder.com/questionTerminal/4c776177d2c04c2494f2555c9fcc1e49
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();
}}
深信服公司福利 851人发布
