模板的:
没看懂题目,示例也很奇怪。看了模板之后觉得很简单。
class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
while(!stack1.empty()){
int temp = stack1.top();
stack1.pop();
stack2.push(temp);
}
int temp = stack2.top();
stack2.pop();
while(!stack2.empty()){
int temp = stack2.top();
stack2.pop();
stack1.push(temp);
}
return temp;
}
private:
stack<int> stack1;
stack<int> stack2;
};