剑指offer31:栈的压入、弹出序列

def isPopOrder(ppush,ppop):
    #     ppush  压入序列
    #     ppop  弹出序列
    if not ppush or len(ppush)!=len(ppop):
        return False
    stack=[]
    for i in ppush:
#         for j in ppush:
        stack.append(i)
        while stack and stack[-1]==ppop[0]:
            stack.pop()
            ppop.pop(0)
    return stack==[]      
ppush=[1,2,3,4,5]          
ppop=[4,5,3,2,1]
isPopOrder(ppush,ppop)
发布了86 篇原创文章 · 获赞 1 · 访问量 8224

猜你喜欢

转载自blog.csdn.net/a1272899331/article/details/104539142