# -*- coding:utf-8 -*-
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if len(pushV)!=len(popV):
return False
elif pushV==popV or pushV==popV[::-1]:
return True
elif len(pushV)==len(popV)==1 and pushV!=popV:
return False
elif pushV[-1]==popV[0]:
return self.IsPopOrder(pushV[:-1], popV[1:])
else:
index=pushV.index(popV[0])
stack,not_stack=pushV[:index],pushV[index+1:]
return self.IsPopOrder(not_stack, popV[1:1+len(not_stack)])and stack[::-1]==popV[1+len(not_stack):]
原文:https://www.cnblogs.com/hit-joseph/p/11910321.html