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)
剑指offer31:栈的压入、弹出序列
猜你喜欢
转载自blog.csdn.net/a1272899331/article/details/104539142
今日推荐
周排行