直接上代码:

class Solution {
public:
    bool IsPopOrder(vector<int> pushV, vector<int> popV) {
        int len = pushV.size();
        stack<int> a_stack;
        int i = 0, j = 0;
        for (; i < len; i++) {
            a_stack.push(pushV[i]);
            while (j < popV.size() && !a_stack.empty() && popV[j] == a_stack.top()) {
                j++;
                a_stack.pop();
            }
        }

        return j == popV.size();
    }
};