用一个栈保存输入push的,当要pop的时候把第一个栈的element pop出放到第二个栈里,然后删除front的元素
class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
while( !stack1.empty()){
int tmp = stack1.top();
stack1.pop();
stack2.push(tmp);
}
int res = stack2.top();
stack2.pop();
while(!stack2.empty()){
int tmp = stack2.top();
stack2.pop();
stack1.push(tmp);
}
return res;
}
private:
stack<int> stack1;
stack<int> stack2;
};