代码如下:
class Solution { public: void push(int node) { s1.push(node); } int pop() { while(!s1.empty()){ s2.push(s1.top()); s1.pop(); }int temp=s2.top(); s2.pop(); while(!s2.empty()){ s1.push(s2.top()); s2.pop(); } return temp; } private: stack<int> s1; stack<int> s2; };
原文:https://www.cnblogs.com/cstdio1/p/11232809.html