1. 思路
当辅助栈最后为空时,说明弹出序列合理
2. 代码
# -*- coding:utf-8 -*-
class Solution:
def IsPopOrder(self, pushV, popV):
# write code here
if pushV[0] != popV[-1]:
return False
stack = []
popIndex = 0
for num in pushV:
stack.append(num)
while stack and popV[popIndex] == stack[-1]:
stack.pop()
popIndex += 1
return not stack