import java.util.ArrayList;

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
      int sizeOfPushStack=pushA.length;
      ArrayList<Integer> auxiliaryList=new ArrayList<Integer>();
      //判断边界条件
        if(pushA==null||popA==null){
            return false;
        }
        //开始扫描
        //定义一个指针,指向输出序列的首部
        int indexOfPopStack=0;
        for(int i=0;i<sizeOfPushStack;i++){
            if(pushA[i]!=popA[indexOfPopStack]&&pushA!=null){
                auxiliaryList.add(pushA[i]);
            }else{
                indexOfPopStack++;
            }
        }

        //对比辅助栈的数据与序列indexOfPopStack开始的数据是否相等
        for(int i=auxiliaryList.size()-1;i>=0;i--){
            if(auxiliaryList.get(i)==popA[indexOfPopStack]){
                auxiliaryList.remove(i);
                indexOfPopStack++;
            }
        }
        //辅助栈为空则表示成功
        return auxiliaryList.isEmpty();
    }
}