From 92244572f0bfb068674c8886818a60111956a494 Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:04 +0800 Subject: [PATCH] =?UTF-8?q?Update=2031.=20=E6=A0=88=E7=9A=84=E5=8E=8B?= =?UTF-8?q?=E5=85=A5=E3=80=81=E5=BC=B9=E5=87=BA=E5=BA=8F=E5=88=97.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/31. 栈的压入、弹出序列.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/notes/31. 栈的压入、弹出序列.md b/notes/31. 栈的压入、弹出序列.md index 69817d96..400a8448 100644 --- a/notes/31. 栈的压入、弹出序列.md +++ b/notes/31. 栈的压入、弹出序列.md @@ -2,7 +2,7 @@ ## 题目链接 -[牛客网](https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106?tpId=13&tqId=11174&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof/) ## 题目描述 @@ -15,13 +15,12 @@ 使用一个栈来模拟压入弹出操作。每次入栈一个元素后,都要判断一下栈顶元素是不是当前出栈序列 popSequence 的第一个元素,如果是的话则执行出栈操作并将 popSequence 往后移一位,继续进行判断。 ```java -public boolean IsPopOrder(int[] pushSequence, int[] popSequence) { - int n = pushSequence.length; +public boolean validateBookSequences(int[] putIn, int[] takeOut) { + int n = putIn.length; Stack stack = new Stack<>(); for (int pushIndex = 0, popIndex = 0; pushIndex < n; pushIndex++) { - stack.push(pushSequence[pushIndex]); - while (popIndex < n && !stack.isEmpty() - && stack.peek() == popSequence[popIndex]) { + stack.push(putIn[pushIndex]); + while (popIndex < n && !stack.isEmpty() && stack.peek() == takeOut[popIndex]) { stack.pop(); popIndex++; }