剑指offer-21-栈的压入、弹出序列
栈的压入、弹出序列
http://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106
# -*- coding:utf-8 -*- class Solution: def IsPopOrder(self, pushV, popV): # write code here queue=[] i,j=0,0 while i<len(pushV): if pushV[i]!=popV[j]: queue.append(pushV[i]) i+=1 else : i+=1 j+=1 while queue and popV[j]==queue[-1]: j+=1 queue.pop(-1) if queue==[]: return True else: return False