题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param pushV int整型一维数组 # @param popV int整型一维数组 # @return bool布尔型 # class Solution: def IsPopOrder(self , pushV: List[int], popV: List[int]) -> bool: if pushV==popV: return True if len(pushV)<=1: if pushV==popV: return True else: return False res=[] for i in range(len(pushV)): if res==[] or res[-1]!=popV[0]: res.append(pushV[i]) while res and res[-1]==popV[0]: popV.pop(0) res.pop(-1) if popV==[]: return True else: return False