155. 最小栈
题目链接:155. 最小栈
代码如下:
class MinStack {
public:stack<int> s_stack;stack<int> min_stack;MinStack() {}void push(int val) {s_stack.push(val);if(min_stack.empty()){min_stack.push(val);}else{min_stack.push(min(val,min_stack.top()));}}void pop() { min_stack.pop();s_stack.pop();}int top() {return s_stack.top();}int getMin() {return min_stack.top();}
};/*** Your MinStack object will be instantiated and called as such:* MinStack* obj = new MinStack();* obj->push(val);* obj->pop();* int param_3 = obj->top();* int param_4 = obj->getMin();*/