题解 | 用两个栈实现队列
import java.util.*;
import java.util.Stack;
public class Solution {
Stack<Integer> stack1 = new Stack<Integer>();
Stack<Integer> stack2 = new Stack<Integer>();
public void push(int node) {
while (!stack1.isEmpty()) {
Integer pop = stack1.pop();
stack2.push(pop);
}
stack1.push(node);
while (!stack2.isEmpty()) {
Integer pop = stack2.pop();
stack1.push(pop);
}
}
public int pop() {
return stack1.pop();
}
}