剑指offer 两个栈实现队列 解法错误修正

push的上一个操作如果是pop,数据全部在out栈,需要全部压入in栈再push新的数才能保证push到队尾
This commit is contained in:
a188616786a
2018-07-19 14:43:54 +08:00
committed by GitHub
parent 4f5c7491fc
commit fd04d7e653

View File

@ -411,6 +411,9 @@ Stack<Integer> in = new Stack<Integer>();
Stack<Integer> out = new Stack<Integer>();
public void push(int node) {
if (in.isEmpty())
while (!out.isEmpty())
in.push(out.pop());
in.push(node);
}