diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index 2dc15d12..6d27553b 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -393,11 +393,14 @@ public void push(int node) { in.push(node); } -public int pop() { +public int pop() throws Exception{ if (out.isEmpty()) { while (!in.isEmpty()) { out.push(in.pop()); } + if (out.isEmpty()){ + throw new Exception("queue is empty"); + } } return out.pop(); }