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++; }