1 class Solution 2 { 3 public: 4 void push(int node) { 5 stack1.push(node); 6 } 7 8 int pop() { 9 if (stack2.empty()) 10 { 11 while (!stack1.empty()) 12 { 13 stack2.push(stack1.top()); 14 stack1.pop(); 15 } 16 } 17 int res = 0; 18 if (!stack2.empty()) 19 { 20 res = stack2.top(); 21 stack2.pop(); 22 } 23 return res; 24 } 25 26 private: 27 stack<int> stack1; 28 stack<int> stack2; 29 };
原文:https://www.cnblogs.com/zzw1024/p/11652164.html