class Solution:
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
i = 0
stack = []
for n in pushed:
stack.append(n)
while i < len(popped) and stack and popped[i] == stack[-1]:
stack.pop()
i += 1
return not stackclass Solution:
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
l = r = 0
for num in pushed:
pushed[l] = num
l += 1
while l > 0 and pushed[l - 1] == popped[r]:
r += 1
l -= 1
return l == 0