标签:style blog color sp div log bs as nbsp
就是用另外一个单调stack来记录最小值就可以了,这个队列单调递减。
class MinStack { public: void push(int x) { st.push(x); if (stm.empty() || stm.top() >= x) stm.push(x); } void pop() { int top = st.top(); st.pop(); if (top <= stm.top()) stm.pop(); } int top() { return st.top(); } int getMin() { return stm.top(); } private: stack<int> st; stack<int> stm; };
标签:style blog color sp div log bs as nbsp
原文地址:http://www.cnblogs.com/x1957/p/4086448.html