题目:http://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6

C++

 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             while (!stack1.empty()) {
11                 stack2.push(stack1.top());
12                 stack1.pop();
13             }
14         }
15         int ret = stack2.top();
16         stack2.pop();
17         return ret;
18     }
19 
20 private:
21     stack<int> stack1;
22     stack<int> stack2;
23 };

 

相关文章:

  • 2022-02-24
  • 2021-08-21
  • 2021-08-30
  • 2022-02-02
  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2021-12-17
  • 2022-01-03
  • 2021-09-22
  • 2021-08-10
  • 2022-01-17
相关资源
相似解决方案