stack_removal_order_checker

This commit is contained in:
Bigsk 2022-06-06 23:54:10 +08:00
parent 7f907700bf
commit cfd9d8db14
2 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,5 @@
# snippets
Favorite code snippets
Favorite code snippets
All code follows the MIT license

View File

@ -0,0 +1,9 @@
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