题目
思路
Code
class Solution
{
public:
void push(int node) {
stack1.push(node);
}
int pop() {
if(stack2.empty()) //注意 ---只有当栈2为空时才能进行压入操作
{
while(!stack1.empty()) //将栈1的元素全部压入栈2
{
stack2.push(stack1.top());
stack1.pop();
}
}
int node = stack2.top();
stack2.pop();
return node;
}
private:
stack<int> stack1;
stack<int> stack2;
}; 
京公网安备 11010502036488号