index
title: 栈的压入 date: 2019-08-21T11:00:41+08:00 draft: false categories: offer
题目
解题思路
public boolean IsPopOrder(int[] pushA, int[] popA) {
if (pushA.length != popA.length) {
return false;
}
if (pushA.length == 0) {
return false;
}
LinkedList<Integer> stack = new LinkedList<>();
int j = 0;
for (int value : pushA) {
stack.addLast(value);
while (stack.peekLast() != null && popA[j] == stack.getLast()) {
j++;
stack.removeLast();
}
}
return stack.isEmpty();
}Last updated