//方案一:

import java.util.*;

public class Solution {

public boolean IsPopOrder(int [] pushA,int [] popA) {

     Stack<Integer> stack =new Stack<Integer>();
    int j=0;

    for(int i=0;i<pushA.length;i++)
    {
        if(pushA[i]==popA[j])
        {
            j++;

            while(!stack.isEmpty()&&j<pushA.length&&stack.peek()==popA[j]){
                    stack.pop();
                    j++;
            }
        }
        else
            stack.push(pushA[i]);

    }

    return stack.isEmpty();
}

}

//方案二:

public class Solution {

public boolean IsPopOrder(int [] pushA,int [] popA) {

     Stack<Integer> stack =new Stack<Integer>();

     int i=0,j=0;
     boolean res=true;

    while(j<pushA.length){

        if(i<pushA.length&&pushA[i]==popA[j])
        {i++;
         j++;
        }

        else if(!stack.isEmpty()&&stack.peek()==popA[j])
        {stack.pop();
         j++;
        }

        else  if(i<pushA.length)
        {stack.push(pushA[i]);
         i++;
        }
        else {res=false;break;}
    }

    return res;
}

}

12-02 15:00