https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
辅助栈
public boolean IsPopOrder(int[] pushA, int[] popA) {
int n = pushA.length;
//辅助栈
Stack<Integer> s = new Stack<>();
//遍历入栈的下标
int i = 0;
//遍历出栈的数组
for (int j = 0; j < n; j++) {
//入栈:栈为空或者栈顶不等于出栈数组
while (i < n && (s.isEmpty() || s.peek() != popA[j])) {
s.push(pushA[i]);
i++;
}
//栈顶等于出栈数组
if (s.peek() == popA[j]) {
s.pop();
} else {
//不匹配序列
return false;
}
}
return true;
}