栈的压入、弹出序列
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106?tpId=13&&tqId=11174&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
# -*- coding:utf-8 -*- class Solution: def IsPopOrder(self, pushV, popV): # write code here if len(pushV)!=len(popV): return False if pushV==None and popV==None: return True stack=[] j=0 for i in range(0,len(popV)): if len(stack)>0: if stack[-1]==popV[i]: stack.pop() continue while (j<len(pushV)): stack.append(pushV[j]) if pushV[j]==popV[i]: stack.pop() j+=1 break j+=1 if len(stack)>0: return False else: return True