1
class Solution:
2
def validateStackSequences(self, pushed: List[int], popped: List[int]) -> bool:
3
stack = []
4
i = 0
5
for num in pushed:
6
stack.append(num) # we are pushing the number to the stack
7
while len(stack) > 0 and stack[len(stack) - 1] == popped[i]:
8
# if the last element of the stack is equal to the popped element
9
stack.pop()
10
i += 1 # we are incrementing i
11
return True if len(stack) == 0 else False

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0