snippets/stack_removal_order_checker.py

9 lines
238 B
Python
Raw Normal View History

2022-06-06 15:54:10 +00:00
def check(in_list: list, out_list: list) -> bool:
stack = []
i = 0
for num in in_list:
stack.append(num)
while stack and stack[-1] == out_list[i]:
stack.pop()
i += 1
return not stack