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())
while(!stack1.isEmpty()){
stack2.push(stack1.pop());
}
return stack2.pop();
}
}
剑指offer9 两个栈实现一个队列
最新推荐文章于 2021-07-27 11:27:59 发布