class Solution {
public boolean isPopOrder(int[] pushV, int[] popV) {
if (pushV.length != popV.length) {
return false;
}
Deque<Integer> stack = new ArrayDeque<>();
int popIndex = 0;
for (int pushItem : pushV) {
stack.push(pushItem);
while(!stack.isEmpty() && stack.peek() == popV[popIndex]) {
stack.pop();
popIndex++;
}
}
return stack.isEmpty();
}
}