class Solution(object):
def validateStackSequences(self, pushed, popped):
"""
:type pushed: List[int]
:type popped: List[int]
:rtype: bool
"""
s, p = [], 0
for t in pushed:
s.append(t)
while s and s[-1] == popped[p]:
s.pop()
p += 1
return len(s) == 0