//代码



import java.util.ArrayList;
import java.util.Stack;

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
      Stack<Integer> stack = new Stack<Integer>(); 
      //stack.push(pushA[0]);
      boolean r = true;
      int i = 0;
      for(int popNum:popA){
          for(i=i; i<pushA.length; i++){
              int pushNum = pushA[i];
              boolean TF = false;
              for(Integer s:stack){
                  if(popNum==s){
                      TF = true;
                      break;
                  }
              }
              if( TF==false ){
                  stack.push(pushNum);
                  //continue;
              }else{
                  int ss = stack.pop();
                  if(ss!=popNum){
                      r = false;
                  }
                  break;
              }

              //最后一个的元素
              if(i == pushA.length-1){
                  int ss = stack.pop();
                  if(ss!=popNum){
                      r = false;
                  }
                  break;
              }


          }
          if(r==false){
              break;
          }
      }
      return r;
    }
}