题解 | #包含min函数的栈#
包含min函数的栈
http://www.nowcoder.com/practice/4c776177d2c04c2494f2555c9fcc1e49
class Solution { public: stack<int> s1; stack<int> s2; void push(int value) { if(s2.empty()||value<=s2.top()) s2.push(value); s1.push(value); } void pop() { if(s2.top()==s1.top()) s2.pop(); s1.pop(); } int top() { return s1.top(); } int min() { return s2.top(); } };