# -*- coding:utf-8 -*-
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
stack=[]
index=0
while index<len(popV):
if popV[index] not in pushV and popV[index] not in stack:
return False
if popV[index] not in stack:
cur=pushV.index(popV[index])
for i in range(cur+1):
stack.append(pushV.pop(0))
stack.pop()
elif stack[-1]==popV[index]:
stack.pop()
else:
return False
index+=1
return True
我的算法之路45--栈的压入、弹出序列
最新推荐文章于 2021-07-23 13:40:40 发布