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