class Solution {
public:
    bool IsPopOrder(vector<int> pushV,vector<int> popV) {
        stack<int> st;//用栈模拟入栈过程
        int i=0,j=0;
        while(j<popV.size()){//对pop序列进行查找
            if(!st.empty()&&st.top()==popV[j]){
                st.pop();
            }else if(i<pushV.size()){
                while(i<pushV.size()&&pushV[i]!=popV[j]){
                    st.push(pushV[i++]);
                }
                if(i==pushV.size())return false;
                i++;
            }else{
                return false;
            }j++;
        }return true;
    }
};