题目描述
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。

import java.util.Stack;

public class Solution {
    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();
    
    public void push(int node) {
        stack1.push(node);
    }
    public int pop() {
        if (stack2.isEmpty()){//栈1弹出的值往栈2push时,栈2必须为空,否则后进栈1的元素压在先进栈1,现在在栈2还未弹出的元素上,导致后进的先弹出
        while(!stack1.isEmpty()){//栈2弹出时,栈1必须为空,否则后进的还在栈1,弹出的是先进栈的
            stack2.push(stack1.pop());
        }
        }
        return stack2.pop();
    }
}```
python版
class Solution:
    def __init__(self):
        self.stack1 = []
        self.stack2 = []
    def push(self, node):
        # write code here
        self.stack1.append(node)
    def pop(self):
        # return xx
        if len(self.stack2) == 0:
            while self.stack1:
                self.stack2.append(self.stack1.pop())
        return self.stack2.pop()