# -*- 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