代码演示:
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();
}
}