使用俩个栈,一个存储最小值,一个整常的值,对于最小值的存储,每次都比较栈顶元素和插入的值,插入2者中较小值。

class Solution {
    stack<int> st;
    stack<int> minst;
public:
    void push(int value) {
       if(minst.empty()) 
       minst.push(value);
       else
        minst.push(std::min(minst.top(),value));
        st.push(value);
    }
    void pop() {
       minst.pop();
       st.pop(); 
    }
    int top() {
        return st.top();
    }
    int min() {
        return minst.top();
    }
};