![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/befaa3417a2a318cd9dcf6e4b6d83e44.png)
代码演示:
package swordfingeroffer;
import java.util.Stack;
public class InterviewQuestion31 {
public boolean IsPopOrder(int[] pushStack, int[] popSer) {
if ((null == pushStack) || (null == popSer) || (pushStack.length == 0) || (popSer.length == 0) ||
(popSer.length != pushStack.length)) {
return false;
}
Stack<Integer> stack = new Stack<>();
int j = 0;
for (int i = 0;i < pushStack.length;i ++) {
stack.push(pushStack[i]);
while (!stack.isEmpty() && (popSer[j] == stack.peek())) {
stack.pop();
j ++;
}
}
return stack.isEmpty();
}
}