946验证栈序列

1
2
3
4
5
6
7
8
9
10
11
12
class Solution:
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
# 入栈 出栈 模拟
stack_ = []
for i in pushed:
stack_.append(i)
while len(stack_)!= 0 and stack_[-1] == popped[0]:
stack_.pop()
popped.pop(0)
if stack_==[]:
return True
else: return False