import java.util.ArrayList;
import java.util.Stack;
public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        int i = 0;//pushA的指针
        int j = 0;//popA的指针
        Stack<Integer> stack = new Stack<>();
        //先压栈,后判断
        stack.push(pushA[i]);
        while(i < pushA.length && j < popA.length){
            if(stack.empty() || stack.peek() != popA[j]){//不相等
                i++;
                if(i == pushA.length){return false;}//i越界,说明都不匹配
                stack.push(pushA[i]);//再次压入一个
            }else{//相等
                stack.pop();//出栈
                j++;
            }
        }
        if(stack.empty()){
            return true;
        }
      return false;
    }
}