LeetCode:155 最小栈

class MinStack {
    Deque<Integer> stack;
    Deque<Integer> min_stack;
    /** initialize your data structure here. */
    public MinStack() {
        stack = new LinkedList<>();
        min_stack = new LinkedList<>();

    }
    
    public void push(int x) {
        stack.push(x);
        if(min_stack.size()!=0)
            min_stack.push(Math.min(min_stack.peek(),x));
        else{
            min_stack.push(x);
        }
    }
    
    public void pop() {
        stack.pop();
        min_stack.pop();
    }
    
    public int top() {
        return stack.peek();
    }
    
    public int getMin() {
        return min_stack.peek();
    }
}
原文地址:https://www.cnblogs.com/dloooooo/p/13766402.html