From fd04d7e6538fb8466e2b9fcf3c55284af535457a Mon Sep 17 00:00:00 2001 From: a188616786a Date: Thu, 19 Jul 2018 14:43:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=91=E6=8C=87offer=20=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E6=A0=88=E5=AE=9E=E7=8E=B0=E9=98=9F=E5=88=97=20=E8=A7=A3?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit push的上一个操作如果是pop,数据全部在out栈,需要全部压入in栈再push新的数才能保证push到队尾 --- notes/剑指 offer 题解.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index c0c5412f..5dd25159 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -411,6 +411,9 @@ Stack in = new Stack(); Stack out = new Stack(); public void push(int node) { + if (in.isEmpty()) + while (!out.isEmpty()) + in.push(out.pop()); in.push(node); }