思路:新建一个栈,将数组A压入栈中,当栈顶元素等于数组B时,就将其出栈,当循环结束时,判断栈是否为空,若为空则返回true.
# -*- coding:utf-8 -*-
class Solution:
    def IsPopOrder(self, pushV, popV):
        # write code here
        if len(pushV) == 0&nbs***bsp;len(popV) == 0&nbs***bsp;len(pushV)!= len(popV):
            return False
        j = 0
        stack = []
        for i in range(len(pushV)):
            stack.append(pushV[i])
            while len(stack)!= 0 and stack[-1] == popV[j]:
                    stack.pop()
                    j+=1
        return True if len(stack)==0 else False

参考资料: